Git – Cleaning up old remote git branches

gitgit-branch

I work from two different computers (A and B) and store a common git remote in the dropbox directory.

Let's say I have two branches, master and devel. Both are tracking their remote counterparts origin/master and origin/devel.

Now while on computer A, I delete branch devel, on local and remote.

git push origin :heads/devel
git branch -d devel

Running git branch -a on computer A, I get the following list of branches.

  • master
  • origin/HEAD
  • origin/master

Running git fetch on computer B, I can remove the local devel branch with git branch -d devel, but I can't remove the remote devel branch.

git push origin :heads/devel returns the following error messages.

error: unable to push to unqualified destination: heads/proxy3d
The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref.
fatal: The remote end hung up unexpectedly

git branch -a still lists origin/devel in the remote branches.

How can I clean up the remote branches from computer B?

Best Answer

First, what is the result of git branch -a on machine B?

Second, you have already deleted heads/devel on origin, so that's why you can't delete it from machine B.

Try

git branch -r -d origin/devel

or

git remote prune origin

or

git fetch origin --prune

and feel free to add --dry-run to the end of your git statement to see the result of running it without actually running it.

Docs for git remote prune and git branch.