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 >
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?’
Did you intend to checkout ‘origin/
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: checkout, git, Pull, Remote Branch
In: Uncategorized · Tagged with: checkout, git, Pull, Remote Branch


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.
on March 29, 2010 at 1:24 pm
Permalink
Thanks,
This help me
on December 10, 2010 at 1:51 am
Permalink
best not use angled brackets as placeholders when you explain shell commands.
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.
on April 7, 2011 at 2:11 am
Permalink
thanks, this was the only way I got this working. Sweating real bad now.
on August 29, 2011 at 6:58 pm
Permalink
Thanks a lot. Do you know how to repull the latest branch?
on December 9, 2011 at 5:29 am
Permalink
@max
git pull doesn’t just that
on April 27, 2012 at 8:50 am
Permalink
thank you so much… i do often have to call pull before checkout for this to work since i deal with new branches often
on July 17, 2012 at 9:52 am
Permalink
If git pull doesn’t work, do a “git remote update”.
on July 20, 2012 at 1:42 am
Permalink
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
on August 2, 2012 at 2:22 am
Permalink
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
on August 2, 2012 at 8:34 pm
Permalink
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?
on August 23, 2012 at 6:03 am
Permalink
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 …
http://gitready.com/intermediate/2009/01/09/checkout-remote-tracked-branch.html
on September 25, 2012 at 7:55 pm
Permalink
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.
on September 27, 2012 at 2:54 pm
Permalink
[...] $ git clone -b my-branch [email protected]:user/my-project.git local-project-directoryor specifically for me:$ git clone -b dev [email protected]:gvinter/my-project.git MyProject Another way to get to that remote, non-master branch without doing weird pulls/branching is stated here: [...]
on March 20, 2013 at 2:21 am
Permalink
@ 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.