1

I converted a Subversion repository to Git a couple weeks ago. I'm left with a bunch of branches I no longer need, but can't delete. What's worse, in the process of trying to get rid of the svn/whatever branches, I now find myself with branches with "origin" duplicated. Here's a fragment of my branch list:

% git branch -a | egrep 'svn/partial|master'
* master
  origin/master
  origin/origin/master
  svn/partial
  remotes/origin/master
  remotes/origin/origin/master
  remotes/svn/partial

I appear to be able to delete the svn/partial branch, but not the remotes/svn/partial branch:

% git branch -D svn/partial
Deleted branch svn/partial (was 373a64c).
% git branch -D remotes/svn/partial
error: branch 'remotes/svn/partial' not found.

If I git-fetch, svn/partial is recreated, and I get another layer of "origin/" branches:

% git push
Everything up-to-date
% git fetch
From .
...
 * [new branch]      origin/origin/origin/master -> origin/origin/origin/master
...
 * [new branch]      svn/partial -> svn/partial

Yikes! They are multiplying like tribbles:

% git br -a | egrep 'svn/partial|master'
* master
  origin/master
  origin/origin/master
  origin/origin/origin/master
  svn/partial
  remotes/origin/master
  remotes/origin/origin/master
  remotes/origin/origin/origin/master
  remotes/svn/partial

How do I fix this?

smontanaro
  • 1,537
  • 3
  • 15
  • 26
  • 2
    possible duplicate of [How do I delete a Git branch both locally and in GitHub?](http://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-in-github) – Jonathan Wakely Feb 14 '13 at 21:00

1 Answers1

1

git branch -d <branch> deletes a local branch. The remote branch isn't in your local repo, so you can't delete it from your local repo.

To delete it from the remote repo there are a few equivalent commands, the canonical one is:

git push origin :svn/partial

This says to push nothing (i.e. a non-existent branch) to the remote branch svn/partial, which will cause the remote branch to become non-existent ... which is Git's way of saying delete it :)

Recent versions of Git support a more friendly syntax:

git push origin --delete svn/partial
Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
  • 7
    And after deleting the remote branches, run `git remote prune origin` to also delete the tracked `remotes/origin/*` branches from your local repository. – robrich Feb 14 '13 at 23:14