Git checkout : updating paths is incompatible with switching branches

标签 git git-checkout remote-branch

我的问题与 Fatal Git error when switching branch 有关.

我尝试使用命令获取远程分支

git checkout -b local-name origin/remote-name

但我收到此错误消息:

fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/remote-name' which can not be resolved as commit?

如果我手动创建一个分支然后 pull 远程分支,它就可以工作,就像创建一个新的克隆并 check out 分支一样。

为什么它在我使用的存储库上不起作用?

最佳答案

我相信当您尝试 checkout 您的本地 git 存储库还不知道的远程分支时会发生这种情况。尝试:

git remote show origin

如果您要 check out 的远程分支在“新远程分支”下而不是“跟踪远程分支”下,那么您需要先获取它们:

git remote update
git fetch

现在它应该可以工作了:

git checkout -b local-name origin/remote-name

关于Git checkout : updating paths is incompatible with switching branches,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/945654/

相关文章:

GIT:设置新 repo 的更好方法

java - 触发 Git 获取,使用 Jenkins 重置

git - 干净的工作树下 `git branch -f <branch_name> <hash>` 和 `git checkout <branch_name>; git reset --hard <hash>` 之间的区别?

Git:使用还原或 checkout 来撤消推送的更改?

Git - 更改分支的跟踪配置

git - 在 Git 中查看已删除的文件

git - 如何在 Git 中将一个分支的特定提交 merge 到另一个分支?

git checkout -p 指定编码

java - 如何使用 JGit 删除远程分支

git clone不带master分支