git 删除本地开发分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47216073/
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
Delete a local development branch
提问by Programmer
I have recently cloned a repo of our development code branch in my system:
我最近在我的系统中克隆了我们开发代码分支的 repo:
git clone https://gitserver.com/product
After the clone was successful I get the below status on query:
克隆成功后,我在查询中得到以下状态:
$ git branch
* develop
I realized that now this branch needs to be deleted, hence:
我意识到现在需要删除这个分支,因此:
$ git checkout develop
Already on 'develop'
Your branch is up-to-date with 'origin/develop'.
$ git branch -d develop
error: Cannot delete branch 'develop' checked out at 'C:/work/test'
I am not sure whether we should try a GIT command or Unix command 'rm -rf' to delete a local develop branch repository? Lastly why no one can delete 'develop' branch.
我不确定我们是否应该尝试使用 GIT 命令或 Unix 命令 'rm -rf' 来删除本地开发分支存储库?最后为什么没有人可以删除“开发”分支。
回答by Nandu Kalidindi
You cannot delete the branch you are currently on.
您无法删除当前所在的分支。
Try creating a new branch
尝试创建一个新分支
git checkout -b new-branch
Then delete the develop branch
然后删除develop分支
git branch -d develop
回答by Víctor López
Adding to Nandu Kalidindi's answer:
添加到 Nandu Kalidindi 的回答中:
When you clone a repo, it will always have a master
branch. This master branch, shouldn'tbe deleted. And if you want to delete it anyway, you must push another branch before, so git will recognize the new pushed branch as the new master branch.
当你克隆一个 repo 时,它总会有一个master
分支。这个主分支,不应该被删除。而且如果你无论如何要删除它,你必须在之前推送另一个分支,所以 git 会将新推送的分支识别为新的 master 分支。
So, in your case, if you want to delete the repo you should try a UNIX command (rm -rf
).
因此,在您的情况下,如果您想删除存储库,您应该尝试使用 UNIX 命令 ( rm -rf
)。
回答by Deeksha Sharma
The branch which you are on currently cannot be deleted so create a new branch
您当前所在的分支无法删除,因此创建一个新分支
git checkout -b new_branch
then delete the branch you want to delete
然后删除要删除的分支
git branch -d develop