Git tracking branches

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

~/code/blog/armmer.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  ').
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 = 
    merge = 
 
    [remote ""] 
    url = 
    fetch = 
 
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/armmer.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 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:armmer/armmer.github.com.git
    fetch = +refs/heads/*:refs/remotes/origin/*

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

Now if I do a git pull I get:

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

It worked. Now back to coding…

Related Articles:

Post Footer automatically generated by Add Post Footer Plugin for wordpress.

About Jason Meridth

Continuously learning software developer trying to not let best be the enemy of better
This entry was posted in git. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

4 Responses to Git tracking branches

  1. Jim Raden says:

    The “helpful” Git message is a few versions behind, I think, rendering it less helpful. Perhaps you have just inspired a bug report. :)

    The refspec format frankly scares me. Even for Git it looks arcane.

    I prefer the following, which sets up the local branch to track the remote branch:

    $ git branch -t branchname remotename/branchname

    Note: if “branchname” already exists locally, you may have to add an “-f” as another parameter, I believe before the branch name.

    And very recently (1.7?) they added the a nifty feature to the checkout command:

    $ git checkout branchname

    If “branchname” is not already a local branch, it automatically creates a tracking branch with that name. Cool, eh?

  2. @Jim

    I use the -t/–track command too. I, unfortunately, have local branches from my git beginnings that weren’t tracked and wanted to post this info in case anyone else comes across it.

    I agree the refspec format seems arcane.

    I didn’t know that checkout was wired to create a local tracking branch automatically now in 1.7. I’m going to play with that tonight.

    Thanks for the additional information.

  3. Roger Pence says:

    Jason–Thanks for turning me on to Git at our local user group meeting a while back. How about writing a little about doing diffs with Git. I’ve pretty much made friends with everything else, but diffs (both at the commit and file level) sometimes drive me nuts.

    Thanks
    rp

  4. @Roger

    I’ll work on it tonight.

    In the mean-time just understand that:

    “git diff” compares your working directory and index/staging
    “git diff –staged” compares your index/staging to your local repository (committed files)
    “git diff HEAD” compares your local reponsitory (committed files) to your working directory

    http://book.git-scm.com/3_comparing_commits_-_git_diff.html
    http://kernel.org/pub/software/scm/git/docs/git-diff.html

    This is not to be read as a RTFM. I’ll write the post tonight.