简体   繁体   English

Git:无法永久删除远程分支

[英]Git: Can't delete remote branch permanently

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.但是在我删除远程分支后,无论我在哪台计算机上,如果我使用“git pull”或“git fetch”,它都会重新拉取那个 new_branch。 I've tried all the prune commands I saw and everything.我已经尝试了所有我看到的修剪命令和一切。 But still it continues to show up.但它仍然继续出现。

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.这将从远程存储库中删除名为new_branch的分支。 (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是远程的本地分支。换句话说,如果您可以 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

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 (删除此分支)(您可以通过单击Restore来撤消更改并使用 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 ,然后删除限制规则,确保默认分支是安全的(主)。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM