Reputation: 935
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.
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.
Upvotes: 21
Views: 28296
Reputation: 14527
In order to remove remote branch:
Option 1: Use git cli (branch name should not contain suffix of 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)
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).
Upvotes: 1
Reputation: 44417
You have to do this to remove the branch on the 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.)
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
.
Upvotes: 44