Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot checkout remote git branch

Tags:

I'm in a github local clone. Below is the list of branches:

$ git branch -a * master   online-demo   remotes/origin/HEAD -> origin/master   remotes/origin/develop   remotes/origin/gh-pages   remotes/origin/master   remotes/origin/online-demo   remotes/pateketrueke/develop   remotes/pateketrueke/gh-pages   remotes/pateketrueke/master 

When I try to checkout a remote branch, I get an error:

$ git checkout develop error: pathspec 'develop' did not match any file(s) known to git. 

I can't figure out where does that come from. I guess I've been doing such checkouts for ages. Maybe I'm missing something. Anyway, I did git fetch, git fetch origin and git pull because I'm running out of ideas and there's still the same error.

like image 675
ducin Avatar asked May 05 '15 22:05

ducin


People also ask

Can you checkout a remote branch in git?

In order to checkout a remote branch you have to first fetch the contents of the branch. In modern versions of Git, you can then checkout the remote branch like a local branch. Older versions of Git require the creation of a new branch based on the remote .

How do I force a branch to checkout?

Force a Checkout You can pass the -f or --force option with the git checkout command to force Git to switch branches, even if you have un-staged changes (in other words, the index of the working tree differs from HEAD ). Basically, it can be used to throw away local changes.

How do I checkout someone else's branch?

If you want to check out a remote branch someone published, you first have to use git fetch . This command downloads the references from your remote repository to your local machine, including the reference to the remote branch. Now all you need to do is use git checkout <remote branch name> .


1 Answers

You don't have any local branch called develop. When doing git checkout develop and no local branches are found, git will understand that you want to make a new local branch called develop, based on a develop branch in a remote repo, if any exists. In your case, you have 2 such branches origin/develop and pateketrueke/develop, so there is an ambiguity.

You can be more explicit about it by using the following form:

git branch develop origin/develop git checkout develop 

or

git branch develop pateketrueke/develop git checkout develop 

depending on what you want.


These can be abbreviated as:

git checkout -b develop origin/develop 

or

git checkout -b develop pateketrueke/develop 
like image 98
Sébastien Dawans Avatar answered Sep 18 '22 15:09

Sébastien Dawans