Git:无法永久删除远程分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24315115/
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
Git: Can't delete remote branch permanently
提问by kamcknig
I know this has been asked, I've seen so my responses on it, but nothing seems to work.
我知道有人问过这个问题,我已经看到了我的回答,但似乎没有任何效果。
Here was my workflow. Create a new branch and work on it. Sometimes I use multiple computers so I pushed it to remote so that I could get it elsewhere
这是我的工作流程。创建一个新分支并对其进行处理。有时我使用多台计算机,所以我将它推送到远程,以便我可以在其他地方获取它
git branch new_branch
git checkout new_branch
git push -u origin new_branch
Do some of my work on one of many computers then merge to master and push.
在多台计算机中的一台上完成我的一些工作,然后合并到 master 和 push。
git checkout master
git merge new_branch
Now I want to delete the branch.
现在我想删除分支。
git branch -d new_branch (this works fine and when I run 'git branch' it only shows local master
git branch -r -d origin/new_branch (now on this computer when i run 'git branch -r' it's gone like it should be)
But after I delete the remote branch, no matter which computer I'm on if I 'git pull' or 'git fetch' it re-pulls that new_branch. I've tried all the prune commands I saw and everything. But still it continues to show up.
但是在我删除远程分支后,无论我在哪台计算机上,如果我 'git pull' 或 'git fetch' 它都会重新拉那个 new_branch。我已经尝试了所有我看到的修剪命令和一切。但它仍然继续出现。
回答by Klas Mellbourn
You have to do this to remove the branch on the remote.
您必须这样做才能删除remote 上的分支。
git push origin --delete new_branch
This will remove the branch called new_branch
from the remote repository. (The new_branch
is a local branch on the remote. To put it another way, if you could cd into the remote repository, making it the local repository, it would have a local branch called new_branch
. That is the branch you are removing with the command above.)
这将删除new_branch
从远程存储库调用的分支。(这new_branch
是远程上的本地分支。换句话说,如果您可以 cd 进入远程存储库,使其成为本地存储库,它将有一个名为 的本地分支new_branch
。这就是您使用上述命令删除的分支.)
When you do
当你做
git branch -r -d origin/new_branch
all that is happening is that you are removing the remote branch pointer that is in your local repository. This last command does not change anything in the remote repository.
发生的所有事情是您正在删除本地存储库中的远程分支指针。最后一条命令不会更改远程存储库中的任何内容。
After having removed the branch on the remote (using the first command above), then git remote prune origin
will start working on your other computers, removing their remote branches origin/new_branch
.
在删除远程分支后(使用上面的第一个命令),然后git remote prune origin
将开始在您的其他计算机上工作,删除他们的远程分支origin/new_branch
。
回答by avivamg
In order to remove remote branch:
为了删除远程分支:
Option 1: Use git cli (branch name should not contain suffix of refs/remotes/origin/)
选项 1:使用 git cli(分支名称不应包含 refs/remotes/origin/ 的后缀)
git push origin --delete <yourBranchName>
Option 2:Go to github -> branches -> search your branch -> click on trashcan
(Delete this branch) (You can undo your changes and restore your branch using Github gui by clicking on Restore)
选项 2:(Go to github -> branches -> search your branch -> click on trashcan
删除此分支)(您可以通过单击“恢复”使用 Github gui 撤消更改并恢复您的分支)
Another Dot:If your'e getting an error message "remote: error: Cannot delete a protected branch"that means that your branch is protected.
In order to get permission to remove protected branch, go to repository in Github -> Settings -> Branches
and then delete restricting rule, make sure default branch is safe (master).
另一个点:如果您收到错误消息“远程:错误:无法删除受保护的分支”,则意味着您的分支受到保护。为了获得删除受保护分支的权限,请转到repository in Github -> Settings -> Branches
然后删除限制规则,确保默认分支是安全的(master)。