Pull A Git Branch from Remote

Up until lately I have been improperly pulling my remote branches to local.  What I mean is I create a new branch locally, push it to remote (GitHub) then pull it onto a designers computer with the following command

(this is not how to do it)

git checkout -b < new_branch >
git pull origin < new_branch >

Instead do

git checkout -b < new_branch > origin/< new_branch >

So real world example would be

git checkout -b newdesign origin/newdesign

Obviously ‘newdesign’ is the branch name.

If you have trouble doing this with an error

fatal: git checkout: updating paths is incompatible with switching branches/forcing
Did you intend to checkout ‘origin/‘ which can not be resolved as commit?’

Then try a git pull first.

git pull

Posted on July 22, 2009 at 1:56 pm by Jordan Carter · Permalink
In: Uncategorized · Tagged with: , , ,

16 Responses

Subscribe to comments via RSS

  1. Written by Pete Andreeson
    on July 28, 2009 at 2:13 am

    I don’t understand why the latter is preferred. They appear to do the same thing.

  2. Written by Emerson Vinicius
    on March 29, 2010 at 1:24 pm

    This help me

  3. Written by Lucid
    on December 10, 2010 at 1:51 am

    best not use angled brackets as placeholders when you explain shell commands.

  4. Written by Anna
    on April 2, 2011 at 1:57 am

    Thanks for the update. I got used to git pull *origin branch_name* and couldn’t figure out why I was unable checkout my new remote branch.

    git pull, even though it gives me a warning, does the first step of pulling new branch names.

  5. Written by me
    on April 7, 2011 at 2:11 am

    thanks, this was the only way I got this working. Sweating real bad now.

  6. Written by max
    on August 29, 2011 at 6:58 pm

    Thanks a lot. Do you know how to repull the latest branch?

  7. Written by dele.o
    on December 9, 2011 at 5:29 am

    git pull doesn’t just that

  8. Written by mehigh
    on April 27, 2012 at 8:50 am

    thank you so much… i do often have to call pull before checkout for this to work since i deal with new branches often

  9. Written by Anna
    on July 17, 2012 at 9:52 am

    If git pull doesn’t work, do a “git remote update”.

  10. Written by JamesOR
    on July 20, 2012 at 1:42 am

    If you’re getting the ‘updating paths’ error you mention in your post, you might need to perform a ‘git fetch’ on the remote you are trying to pull the new branch from.

    git fetch remote_name
    git checkout -b branch_name remote_name/branch_name

  11. Written by rowgm
    on August 2, 2012 at 2:22 am

    I only have to use git pull, without a branch, and all the rest is done by default by git. Check it out… Just:

    git pull

    and you can see the others local/remote branches with:
    git branch -r

    and you are now able to checkout those branches

  12. Written by Piero Campa
    on August 2, 2012 at 8:34 pm

    In my case here, git expects a commit instead of a remote branch.. Any clue?

    $ git checkout -b /
    fatal: git checkout: updating paths is incompatible with switching branches.
    Did you intend to checkout ‘some/path//’ which can not be resolved as commit?

  13. Written by bwanamarko
    on August 23, 2012 at 6:03 am

    Much easier to just do:

    git checkout -t /

    For example …

    git checkout -t upstream/dev

    … for checking out the “dev” branch from the “upstream” remote.

    Credit goes to git ready …

  14. Written by you
    on September 25, 2012 at 7:55 pm

    If you see the error described above, and you don’t want to do a “git pull”, you can do a “git remote update” instead.

  15. Written by JD Isaacks
    on March 20, 2013 at 2:21 am

    @ Pete Andreeson
    > I don’t understand why the latter is preferred. They appear to do the same thing.

    No they don’t, if you have commits in your current branch then run: git checkout -b

    the new branch is based on your current branch and you may have just put commits into your local that you did not intend to. Then when you run:

    git pull origin you will be automatically merging with the commits form the previous branch.

Subscribe to comments via RSS

Leave a Reply