64

I'am using git as scm of choice but have to use a svn-repo. I can create a svn-remote-branch like this:

git svn branch the_branch

But how can i delete the remote branch?

DerKlops
  • 1,249
  • 1
  • 12
  • 24

4 Answers4

88

Currently, it is not possible to delete an SVN branch using git-svn. But it is easy to delete the branch using SVN, without even having to check it out. So simply type

svn rm $URL/branches/the_branch

Please note that deleting a Subversion branch does not cause it to be deleted from the git-svn repository. (This is intentional, because deleting a Subversion branch does not cause any information loss, whereas deleting a git branch causes its existence to be forgotten following the next git garbage collection.) So if you want the remote SVN branch to be deleted from your git repository, you have to do it manually:

git branch -D -r the_branch
rm -rf .git/svn/the_branch

OR
rm -rf .git/svn/refs/remotes/f8745/ (for newer versions)

To delete a git branch that corresponds to a Subversion tag, the commands are slightly different:

git branch -D -r tags/the_tag
rm -rf .git/svn/tags/the_tag
Sunny Milenov
  • 21,990
  • 6
  • 80
  • 106
mhagger
  • 2,687
  • 18
  • 13
  • 1
    As Stephen C speculates in another answer, the exact structure of the tree in .git/svn depends on how you set up your git-svn configuration. That said, for most common configurations, it shouldn't be hard to figure out the right subdirectories to delete. – ipmcc Mar 17 '11 at 18:51
  • 1
    would not `git gc` or `git svn gc` detect and delete the correct files without the user aving to guess? – Ben Page Sep 28 '11 at 13:31
  • 1
    Ben: the "rm -rf" commands delete git-svn metadata for the branch. This information is not cleaned up by "git gc" or "git svn gc". – mhagger Sep 30 '11 at 13:09
  • If you're doing this to apply a new refspec for your tags you'll also need to edit `.git/svn/.metadata` to set back `tags-maxRev`. – Ben Challenor May 23 '13 at 13:51
  • "deleting a Subversion branch does not cause any information loss, whereas deleting a git branch causes its existence to be forgotten" — that's not really a correct way to put it: deleting a git branch just deletes the pointer to the last commit in the branch, not the history of the branch—this is equivalent to how SVN operates when a branch is deleted. – Erik Kaplun Aug 14 '13 at 19:47
  • 1
    Erik, you are mistaken. If a git branch is deleted, then any of the commits on that branch that were never merged to another branch are subject to being garbage-collected and lost irretrievably (after a grace period of two weeks by default). A deleted Subversion branch, on the other hand, is forever retained in the repository's history and can be viewed, checked out, etc. from a Subversion revision prior to the branch's deletion. – mhagger Aug 17 '13 at 15:47
  • This technique does not prevent the branch from appearing later in other git-svn clones. Clones will also need to manually remove the branch as shown above. – Bobby Eickhoff Oct 31 '13 at 12:54
  • 2
    If git has a complete history of the repo, and that branch did exist in the repo, what's the deal with remove things inside .git directory? This is totally misleading newcommers to git from svn. – albfan May 22 '14 at 07:48
  • @albfan: it kind of is, but that's why `git branch -d ` responds with `error: The branch 'unmerged_branch' is not fully merged. If you are sure you want to delete it, run 'git branch -D umerged_branch'.` Once the branch is merged, it's no longer required (because the entire branch history is retained, and you can go back if you want even without it). – naught101 Apr 19 '16 at 02:03
7

This worked well for me, thanks. Not sure if my environment is just different or this was changed in a more recent version of git, but the svn branch dirs were located in .git/svn/refs/remotes/ which was simple enough to find from the original instructions, changing the rm command to:

rm -rf .git/svn/refs/remotes/the_branch

Not sure about the tags since I don't use those much.

Stephen C
  • 659
  • 6
  • 9
2

Opps, the top answer was wrote at 2009, now the correct way to delete a remote tag is

svn rm svn://dev.in/branches/ios_20130709150855_39721/
git branch -d -r ios_20130709150855_39721
alswl
  • 1,265
  • 11
  • 11
0

As of 2017, we still don't have git svn branch --delete. (-d option is there but it is for mystic --destination)

As described in other answers, manual steps are:

  1. Print commit message: git log -1 $commit
  2. In the commit message, locate git-svn-id: $url line
  3. Remove SVN branch: svn rm $url

I made an alias to automate these steps:

[alias]
    svn-rm-branch = "!f() { if git_svn_id=\"$(git log -1 --format=%B \"$@\" | grep -o '^git-svn-id:[^@]*')\" ; then svn rm --editor-cmd=\"$(git var GIT_EDITOR)\" \"$(echo $git_svn_id | cut -d' ' -f 2)\" ; else echo No git-svn-id in the message of the commit \"$(git rev-parse \"$@\")\" 1>&2; fi }; f"
snipsnipsnip
  • 2,268
  • 2
  • 33
  • 34