Reputation: 2841
I'm trying to checkout a remote branch which doesn't exist locally.
git checkout -b branch_name origin/branch_name
gives:
fatal: Cannot update paths and switch to branch 'branch_name' at the same time.
Did you intend to checkout 'origin/branch_name' which can not be resolved as commit?
git branch -a
doesn't show the branch I'm trying to checkout.
How can I checkout the remote branch locally?
Upvotes: 6
Views: 10919
Reputation: 1482
Try this
git remote update
git fetch
git checkout -b branch_name origin/branch_name
Your local repo is not aware of the remote branch.
Upvotes: 12
Reputation: 18843
If git branch -a
doesn't show the branch you want, it doesn't exist on the remote either - the 'origin/branch_name' which can not be resolved
message confirms that.
First, run git fetch origin
to sync your local snapshot of the remote and see if the remote branch appears in git branch -a
. In that case your current command should work, or there are many other versions in Checkout remote Git branch.
If the remote branch doesn't appear, you'll need to create it with
git checkout -b branch_name
git push -u origin branch_name
You might also want to check git remote -v
to make sure your remote exists and is called origin
.
Upvotes: 2