Deleting an SVN branch

SvnVersion ControlBranching and-Merging

Svn Problem Overview


I created a branch of an SVN project called 'features', and now whenever I try to update said project, it brings with it a features folder, which contains another copy of the project from the branch.

Is there a way to remove the branch from the repository completely so that this doesn't happen any more?

Svn Solutions


Solution 1 - Svn

Sure: svn rm the unwanted folder, and commit.

To avoid this situation in the future, I would follow the recommended layout for SVN projects:

  • Put your code in the /someproject/trunk folder (or just /trunk if you want to put only one project in the repository)
  • Created branches as /someproject/branches/somebranch
  • Put tags under /someproject/tags

Now when you check out a working copy, be sure to check out only trunk or some individual branch. Don't check everything out in one huge working copy containing all branches.1

1Unless you know what you're doing, in which case you know how to create shallow working copies.

Solution 2 - Svn

For those using TortoiseSVN, you can accomplish this by using the Repository Browser (it's labeled "Repo-browser" in the context menu.)

context menu

Find the branch folder you want to delete, right-click it, and select "Delete."

deleting the folder

Enter your commit message, and you're done.

committing

Solution 3 - Svn

Assuming this branch isn't an external or a symlink, removing the branch should be as simple as:

svn rm branches/< mybranch >

svn ci -m "message"

If you'd like to do this in the repository then update to remove it from your working copy you can do something like:

svn rm http://< myurl >/< myrepo >/branches/< mybranch >

Then run:

svn update

Solution 4 - Svn

You can also delete the branch on the remote directly. Having done that, the next update will remove it from your working copy.

svn rm "^/reponame/branches/name_of_branch" -m "cleaning up old branch name_of_branch"

The ^ is short for the URL of the remote, as seen in 'svn info'. The double quotes are necessary on Windows command line, because ^ is a special character.

This command will also work if you have never checked out the branch.

Solution 5 - Svn

Command to delete a branch is as follows:

svn delete -m "<your message>" <branch url>

If you wish to not fetch/checkout the entire repo, execute the following command on your terminal:

  1. get the absolute path of the directory that will contain your working copy
    > pwd
  2. Start svn code checkout
    > svn checkout <branch url> <absolute path from point 1>

The above steps will get you the files inside the branch folder and not the entire folder.

Solution 6 - Svn

You can delete the features folder just like any other in your checkout then commit the change.

To prevent this in the future I suggest you follow the naming conventions for SVN layout.

Either give each project a trunk, branches, tags folder when they are created.

svn
+ project1
  + trunk
    + src
    + etc...
  + branches
    + features
      + src
      + etc...
  + tags
+ project2
  + trunk
  + branches
  + tags

Solution 7 - Svn

From the working copy:

svn rm branches/features
svn commit -m "delete stale feature branch"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGStoView Question on Stackoverflow
Solution 1 - SvnWim CoenenView Answer on Stackoverflow
Solution 2 - Svn2rs2tsView Answer on Stackoverflow
Solution 3 - SvngrmartinView Answer on Stackoverflow
Solution 4 - SvnMathKidView Answer on Stackoverflow
Solution 5 - SvnAlvin ChettiarView Answer on Stackoverflow
Solution 6 - SvnChris NavaView Answer on Stackoverflow
Solution 7 - SvnsbiView Answer on Stackoverflow