Basic usage of git-svn

This is a small guide I wrote for my own convenience when I recently was converting an SVN repository to a Git repository. I’ve published it here so that I can easily look up the things I need to remember..

I’ve found most of these examples in the excellent official git-svn documentation.

Cloning the SVN repository

git svn clone <repo-url>

Adding another remote

git remote add <remote-name> <remote-url>

Fetching and rebasing changes from SVN

git svn fetch && git svn rebase

Note that the git-svn documentation has a section discussing rebase vs pull/merge:

Prefer to use git svn rebase or git rebase, rather than git pull or git merge to synchronize unintegrated commits with a git svn branch. Doing so will keep the history of unintegrated commits linear with respect to the upstream SVN repository and allow the use of the preferred git svn dcommit subcommand to push unintegrated commits back into SVN.

Doing work and pushing to SVN

git add <file>
git commit -m "<commit message>"
git svn dcommit # This will push your changes to the SVN repository

Pushing to other remotes

git push <remote-name>

See what will be pushed to SVN

git diff git-svn HEAD # Assuming your remote SVN branch is called git-svn

git svn dcommit --dry-run

Receive a weekly update in your inbox

I'd very much appreciate it if you'd be interested in getting an email delivered directly to your inbox every Sunday morning at 9AM with a summary of my tech related blog posts from the last week. I will not in any way use your email address for anything else. That's a promise.

Leave a Comment