A few short notes about how to use git svn

This page gives a few notes how to use git using Subversion as backend. I prefer working with git, but I appreciate the flexibility and simplicity of a Subversion repository, especially when it comes to creating a new project in an existing repository.

This is just a short aide-mémoire mostly for my own benefit, heavily based on the excellent article Effectively Using Git With Subversion.

Create a Subversion sub-project

The following command creates the project myproject under the repo repository.

svn mkdir --parents https://example.com/svn/repo/myproject/{trunk,tags,branches} -m "Created myproject"

It is recommended to create a repository in the standard layout, that is with the trunk, tags and branches folders.

Working with git svn

Use git svn clone to clone a project. If the project uses the standard layout, then you should use the -s option when cloning the repository, omitting the trunk part of the repository path:

git svn clone -s https://example.com/svn/repo/myproject

Once the repository is checked out, use your normal git workflow as usual. Commits are local (as you would expect in git). To fetch or push work from and to the remote server, use the git svn rebase command:

git svn rebase

It is necessary to have a clean repository when using the git svn rebase command, otherwise git will remind you to commit or stash your work beforehand.

Push your changes to the SVN server using the git svn dcommit command.

git svn dcommit

Stash your work when pushing or pulling to and from the server

If your local repository is modified, then all git svn dcommit or git svn dcommit will fail with an error like this:

$ git svn rebase
path/to/file1: needs update
path/to/file2: needs update
update-index --refresh: command returned error: 1

You can work around this by stashing your local work, executing the git svn commands and popping the work form the stash. The git stash command works like a stack, which means you can have multiple level of stashed work.

$ git stash save
$ git svn rebase
…
$ git stash pop