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)

#DON’T DO THIS
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.

UPDATE:
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

Related Posts

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

7 Responses

Subscribe to comments via RSS

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

    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
    Permalink

    Thanks,
    This help me

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

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

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

    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
    Permalink

    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
    Permalink

    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
    Permalink

    @max
    git pull doesn’t just that

Subscribe to comments via RSS

Leave a Reply