Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Can't delete remote branch permanently

Tags:

git

branch

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.

like image 910
kamcknig Avatar asked Jun 19 '14 19:06

kamcknig


People also ask

How do I permanently delete a branch in git?

Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.

Why can't I delete my git branch?

If the branch contains unmerged changes, though, Git will refuse to delete it. If you're sure you want to do it, you'll have to force the deletion by replacing the -d parameter with an uppercase D: It's like you're pushing—sending—the order to delete the branch to the remote repository.

What is the command to delete a branch in your remote repository?

It should be noted that running git push origin --delete <branch> , as far as I can tell, ALSO deletes the locally-stored remote-tracking branch named origin/branch . So, to delete the remote branch AND locally-stored remote-tracking branch in one command, just use git push origin --delete <branch> .

How do you clean a remote branch?

In order to clean up remote tracking branches, meaning deleting references to non-existing remote branches, use the “git remote prune” command and specify the remote name. In order to find the name of your current configured remotes, run the “git remote” command with the “-v” option.


1 Answers

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.

like image 151
Klas Mellbourn Avatar answered Sep 23 '22 03:09

Klas Mellbourn