Jason Meridth

Learn, Converse, Share

Git Tracking Branches

UPDATE: 22 Feb 2013 - San Atonio

23 Mar 2010 - San Antonio

I have encountered this message multiple times when dealing with Git:

~/code/blog/jmeridth.github.com(master) > git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:

    [branch "master"]
    remote = <nickname>
    merge = <remote-ref>

    [remote "<nickname>"]
    url = <url>
    fetch = <refspec>

See git-config(1) for details.

and I’ve been waiting for it again so that I can blog about it. What this means is that the local master branch of my github pages repository is not tracking a remote branch. The quickest way to get around this would be for me to explicitly state the remote name and branch:

~/code/blog/jmeridth.github.com(master) > git pull origin master

and it would pull successfully. Well, I don’t want to have to specify the remote and branch. The easiest way to do this is:

START CURRENT: set the upstream (remote) branch that your local branch is matched to:

git branch --set-upstream my_branch origin/my_branch

END CURRENT

START OLD: …to edit the configuration file as suggested and add the following (at least in my case):

    [branch "master"]
    remote = origin
    merge = refs/heads/master

    [remote "origin"]
    url = git@github.com:jmeridth/jmeridth.github.com.git
    fetch = +refs/heads/*:refs/remotes/origin/*

The +refs/heads/:refs/remotes/origin/ notation is what is called the refspec format.

END OLD

Now if I do a git pull I get:

~/code/blog/jmeridth.github.com(master) > git pull
Already up-to-date.

It worked. Now back to coding…

Comments