cannot checkout remote git branch

只谈情不闲聊 提交于 2020-01-01 04:24:45

问题


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.


回答1:


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



回答2:


You can try checking out the full SHA commit



来源:https://stackoverflow.com/questions/30064195/cannot-checkout-remote-git-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!