Skip to main content

Using Subversion with Git Svn

·2 mins

I’ve only ever known git and github, so when I just started a new job that used subversion I had to learn a few things to get it working. Eventually I found git svn and started using that instead of just subversion (I missed working locally).

Initializing the repo #

Since I only wanted to use certain branches of the codebase, I had to run the initial clone to only use subversions trunk (subversions version of a master branch) and the branches that I needed.

git svn clone http://repo.com/path/ -T trunk -b /path/to/branches -t tags

The -T is for the trunk, -b for the branches, and -t for the tags. I left off the tags for my clone, as the repo is quite large and it took quite a while just to download the trunk and branches.

If the download gets interrupted for any reason you can just continue where it left off by using git svn fetch.

Ignoring files #

You can easily generate a .gitignore based on subversions props by running:

git svn show-ignore >> .gitignore

Since I did not want to introduce a .gitignore into the repo, I would edit the exclude file in .git/info/exclude if I needed anything ignored.

Working from branches #

You’ll want to track a remote branch and then have it checked out in order to work locally.

git checkout -b local-foo -t remotes/foo

Try to prepend a local branch with something when checking it out to better keep track of what’s local and what’s remote.

To see all available remote branches use git branch -r.

Updating local files #

Instead of using svn update to pull in new changes we end up using these commands:

git svn fetch <*branch>
git svn rebase <*branch>

fetch will get the updates and rebase will put them in locally.

Committing changes #

To commit changes you run the typical git workflow, by staging the files and then committing them to record the changes.

git add file-to-stage.txt
git commit -m "My message"

These changes are only stored locally. To commit them to the subversion repo you have to run git svn dcommit. This will update subversion’s respective branch. Make sure to fetch and rebase before doing so if you’re not the only one working on a branch.

More information on the subject #