1

I'm new to git and I'm working through a tutorial on setting up subModules. I'm trying to understand all the commands and getting hung up on the lines below.

git config branch.master.remote origin
git config branch.master.merge refs/heads/master

Can someone explain what git config does and how to interpret

branch.master.remote
branch.master.merge

https://git.wiki.kernel.org/index.php/GitSubmoduleTutorial

aynber
  • 22,380
  • 8
  • 50
  • 63
Ben Pearce
  • 6,884
  • 18
  • 70
  • 127
  • 2
    Try `git config --help`. – Robin Green Nov 24 '13 at 22:15
  • `git config` is used to query or set configuration options for git. The [git scm book](http://git-scm.com/book/en/Customizing-Git-Git-Configuration) has a discussion on common options you might be interested in, and they're all discussed in the man page (`man git-config`, which does the same as `git config --help` @RobinGreen pointed out). – simont Nov 25 '13 at 01:07

2 Answers2

2

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.

elmart
  • 2,324
  • 15
  • 17
  • 1
    I wouldn't mess with branch config directly, but I agree it is important to see what is going on, which you details a bit more than in my own answer. +1 – VonC Nov 26 '13 at 06:17
0

By default, git config will modify the local config for your current git repo.
(There are three levels of config: system, global and local)

The git config branch.master.xxx you mention is for setting up an upstream branch to your local branch master, in order for your local repo to know what and where to push to from the master branch.

That tutorial is quite old, and nowadays (1.8.0+), we would use:

git branch -u origin/master master

That would modify the same config file, but you wouldn't have to be aware of the branch config syntax.

And you would be able to review all the upstream branches with git branch:

git branch -avv

Specifying an upstream branch is mandatory for the first push, as explained in "Why do I need to explicitly push a new branch?".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250