To be able to merge changes from an upstream branch into one of your local branches, you need two pieces of info:
- The remote where the upstream branch lives.
- The name of the upstream branch.
With that, and once you have your target local branch checked out, you can issue the following command:
git pull <upstream_remote> <upstream_branch>
to do the intended merge.
The most common case, merging master branch of remote origin into your local master branch, would then be:
git pull origin master
But it would be tiresome having to type that again and again. So, you can save some typing saying to git to remember those two pieces of info (remote and branch), so that you can type just git pull
.
That's what you git config
commands are doing. Remembering, for your local branch master, the two needed pieces of info:
git config branch.master.remote origin
"When pulling into master, use remote origin"
git config branch.master.merge refs/heads/master
"When pulling into master, use branch master of remote"
As you see, concepts are easy. It's just the syntax that's a bit convoluted.
Two final notes on that:
- refs/heads/master is the name of the remote branch as seen by the remote repo.
- refs/heads/master is canonical form for what is normally referred as just master. We use canonical names in certain places of config.
Lastly, as @VonC sai, we would nowadays do that through more polished/simple commands, but I think it's worth to know what git is doing under the covers, and the git config commands nicely expose it in this case.