I’m not a big fan of Subversion but I’m madly in love with Git! So much that when I have to use Subversion, I create a Git repository within my locally checked out Subversion branch. This is really easy to do, and only takes four simple steps:
- Navigate to the directory that contains your Subversion branch copy
and use the
git initcommand to create a repository.
- Create a .gitignore file and add a filter to ignore .svn directories (plus everything else that should be ignored, of course).
git committo create an initial commit with the .gitignore file and all code.
- Configure Subversion to ignore the .git directory.
Now you’re ready to work some Git magic! I won’t go into details, but here are a few things that I find very useful:
- Use the
git resetcommand to undo local changes. (Yeah, I know you can use Subversion’s revert command too.)
- Use the
git stashcommand to temporarily save changes.
- Create commits every now and then as “check points”. This is definitively not how you should use Git, but in this context it can save a lot of time. Especially if you work with the Visual Studio WinForms designer, which happily gets into an unrecoverable state every now or then! (Just had to get that off my chest!)
- Create separate commits for each Subversion update you do. While
such a commit is unlikely to be particularly coherent (after all, it
can include work from several of your co-workers), you now have a
way to pinpoint when bugs were introduced. The
git bisectcommand is immensely useful for this purpose, in particular together with a small test runner script.
- Use the
git checkoutcommand to quickly create branches to experiment or try out ideas.
Use branching to facilitate “offline work”. For example, if you worked on a copy of the code somewhere else but accidentally did a Subversion update in the main branch copy, you can:
- Stash the changes from the update,
- create a new branch,
- copy your code into that branch,
- create a commit,
- switch back to the main branch, and finally
- merge from the separate branch using the
Would you like to add anything to the list?