如何切换到分支名称中带有正斜杠的远程分支?

时间:2021-05-19 11:52:38

标签: git

我正在尝试结帐到远程分支,但如果分支名称中有斜杠,则这不起作用:

$ git checkout --track origin/feat/add_posts
fatal: 'origin/feat/add_posts' is not a commit and a branch 'feat/add_posts' cannot be created from it

这个问题的解决方案有点长,可能会导致一些错误,因为我需要知道我需要切换到的分支的父级是什么,这样才不会发生冲突。

命令 for-each-ref 显示:

git for-each-ref | grep feat/add_posts
369006c638a0db7c344d3d6b66c08945c273d4ee commit refs/heads/feat/add_posts
f5ee8ce4c7f9b8213fa33f4abb88d8d13625ca62 commit refs/remotes/origin/feat/add_posts

我使用:

git checkout -b feat/add_posts
git pull origin feat/add_posts
git reset --hard origin/feat/add_posts

它有效,但有没有更简单的方法?

更新:它只在第一次显示(如果我没有这个分支),所以如果我过去有这个分支但我删除了它,我可以结帐到它没有任何问题。

git checkout feat/add_posts
Branch 'feat/add_posts' set up to track remote branch 'feat/add_posts' from 'origin'.
Switched to a new branch 'feat/add_posts'

0 个答案:

没有答案
相关问题