Mapping a local branch to a remote branch in GIT

If you’ve created a git repository using the following steps:

  1. Created a local git repository using “git init .”
  2. Created a remote repository on github.com or another host
  3. Added that remote to the local repository using “git add remote origin <path to remote repo>”

Then you might be in a state where your local master is not mapped to the remote master. To fix that run the following command:

git branch --set-upstream master origin/master

I suspect that in step 3 there could be a way to specify the mapping so it doesn’t have to be done later explicitly, but I’m not aware of it currently.

Mapping a local branch to a remote branch in GIT