Search code examples
gitbranchgit-remote

how to checkout a remote branch


I can see two remote branches in my local repository:

$ git branch -a
  remote/origin/master
  remote/origin/feature1

I actually have four branches in my remote repository. How can checkout the 3rd or 4th branch to my local?

I've tried lots of commands by searching internet, none of them worked for me. I've not problem to get updates on master and feature1 branches from remote to local though.


Solution

  • This:

    [remote "origin"]
        url = <url>
        fetch = +refs/heads/feature1:refs/remotes/origin/feature1
        fetch = +refs/heads/master:refs/remotes/origin/master
    

    is the source of the problem. Here, you have instructed your Git that regardless of what branches exist in the Git over on origin, you want your Git to take and remember only feature1 and master, which you will call origin/feature1 and origin/master.

    The default standard fetch setting for origin, if you don't change it, is:

    fetch = +refs/heads/*:refs/remotes/origin/*
    

    If you had this setting, everything would just work automatically.

    (The question then becomes: why did you stop using the standard, default setting, when you seem to want behavior provided by the standard, default setting? Edit: and apparently the answer to that is: you didn't, Eclipse / EGit did.)