【问题标题】:Git: how to checkout new remote branch?Git:如何签出新的远程分支?
【发布时间】:2015-09-26 00:31:41
【问题描述】:

我正在尝试检查本地不存在的远程分支。

git checkout -b branch_name origin/branch_name

给予:

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 没有显示我要结帐的分支。

如何在本地签出远程分支?

【问题讨论】:

  • Checkout remote Git branch 的可能重复项
  • 我确实尝试了该问题的解决方案,但没有奏效。
  • 确保在尝试签出分支之前先发送git fetch...
  • @zoe 为什么我的主页突然变成了你编辑的问题?
  • @hobbs 清理checkout 标签。

标签: git github branch git-checkout git-remote


【解决方案1】:

试试这个

git remote update
git fetch
git checkout -b branch_name origin/branch_name

您的本地仓库不知道远程分支。

【讨论】:

  • 我试过了,但没用。结帐仍然给出相同的错误消息(致命:无法更新路径并同时切换到分支'branch_name')。
  • 前两个命令有效,但git checkout -b branch_name origin/branch_name 只是给出相同的错误“致命:无法更新路径并同时切换到分支'branch_name'。”在 git 2.12 上
【解决方案2】:

如果git branch -a 没有显示您想要的分支,那么它也不存在于远程 - 'origin/branch_name' which can not be resolved 消息证实了这一点。

首先,运行git fetch origin来同步远程的本地快照,看看远程分支是否出现在git branch -a中。在这种情况下,您当前的命令应该可以工作,或者Checkout remote Git branch 中有许多其他版本。

如果远程分支没有出现,你需要用

创建它
git checkout -b branch_name
git push -u origin branch_name

您可能还想检查git remote -v 以确保您的遥控器存在并且被称为origin。

【讨论】:

  • 远程分支确实存在。 git branch -a 显示:develop * CurrentBranch remotes/origin/HEAD -> origin/develop remotes/origin/develop 我确实尝试过 git fetch origin 但它没有任何区别。 git remote -v 显示:origin github.com/reponame/reponame.git (fetch) origin github.com/reponame/reponame.git (push)
  • 看来origin 知道的唯一分支是develop。你想检查哪个分支你看到origin有?
  • 我要签出的分支称为develop2。我可以在 github 上看到分支,但它没有出现在我的命令输出中。
  • develop2 是否存在于 GitHub 上与您的 origin 指向的同一 user/repo 中?如果存储库是分叉的,它可能位于另一个副本中,您需要将其添加为第二个远程。
  • 听起来你的第一台计算机的副本可能发生了一些有趣的事情,这将很难进一步帮助调试。我会尝试git fetch --all 并在你的机器之间比较.git/config,然后考虑一个新的git clone。
猜你喜欢
  • 2010-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-07
  • 2022-01-11
  • 1970-01-01
相关资源
最近更新 更多