简体   繁体   English

无法签出远程 git 分支

[英]cannot checkout remote git branch

I'm in a github local clone.我在 github 本地克隆中。 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.无论如何,我做了git fetchgit fetch origingit pull ,因为我的想法已经用完了,但仍然有同样的错误。

You don't have any local branch called develop .您没有任何名为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.当执行git checkout develop并且没有找到本地分支时,git 会理解您想要创建一个名为develop的新本地分支,基于远程仓库中的develop分支(如果存在)。 In your case, you have 2 such branches origin/develop and pateketrueke/develop , so there is an ambiguity.在您的情况下,您有 2 个这样的分支origin/developpateketrueke/develop ,因此存在歧义。

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

git checkout -b "name of branch" git checkout -b "分支名称"

git pull origin "name of branch" git pull origin “分支名称”

您可以尝试查看完整的 SHA 提交

Try below commands in sequence:按顺序尝试以下命令:

git fetch
git checkout "your_branch_name"

How it works:怎么运行的:

If your branch is new in git, fetch command fetch the names and later your can use git checkout command to checkout the branch.如果您的分支是 git 中的新分支,请使用 fetch 命令获取名称,然后您可以使用 git checkout 命令签出分支。

To view all the branches you can use要查看您可以使用的所有分支

git branch -a

In my case I had to refetch using在我的例子中,我不得不重新使用

git fetch origin --refetch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM