在 git 裸仓库中切换当前分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4468322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:51:10  来源:igfitidea点击:

Switch current branch in git bare repository

gitgit-branchgit-checkout

提问by Ankur

I actually want to remove a branch in the bare repository i am working with, but this task hits a dead end because I cannot switch away from the master repository without a 'work tree' which a bare repository does not have.

我实际上想删除我正在使用的裸存储库中的一个分支,但是这个任务遇到了死胡同,因为如果没有裸存储库没有的“工作树”,我无法从主存储库切换。

When I run git branch -d masterthe output is:

当我运行时git branch -d master,输出是:

error: Cannot delete the branch 'master' which you are currently on.

So I try to switch to another branch called 'develop' by running git checkout developand the output is:

所以我尝试通过运行切换到另一个名为“develop”的分支git checkout develop,输出是:

fatal: This operation must be run in a work tree

回答by cdhowie

Try this instead of git checkout:

试试这个而不是git checkout

git symbolic-ref HEAD refs/heads/develop

Then you should be able to delete master.

然后你应该可以删除master。