Git and Subversion Cheat Sheet

Git and Subversion are the flavour of the month for source control time machines. I’ve used just about every source control system that’s been made over the years including RCS, PVCS, SourceSafe, ClearCase, Perforce and CVS. There’s a nice history of version control systems here. Here’s my cheat sheet (for Linux / OSX / Cygwin) users.

Install Tools

Works for me on Ubuntu 12.04 LTS:
sudo apt-get install git-core gitg subversion

Remove All Subversion Stuff

Especially useful if you’ve just downloaded a snapshot of source which you’re going to manage locally, e.g. with Git:
find ./ -name ".svn" | xargs rm -Rf
Obviously you can do something similar to nuke the Git-ness from a directory tree, too.
If you’ve forgotten to remove all the svn / Subversion cruft from some source that you’ve downloadaded and copied into your project, there is a cure:
git filter-branch --tree-filter 'rm -rf .svn' HEAD

Start a local Git Repository

Change directory to the root of your project’s source. Create a text file called .gitignore in which you list all the directories and file (and file patterns) that you don’t want managed by git. For example, here’s one for Android projects:
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
*.apk
*.ap_
*.dex
*.class

Then initialise the Git repository.
git init
git add .
git commit -ma "Here's what I've just done."

Permanently Removing Stuff From Git

Forgot to add some things to .gitignore? Forgot to clear out the .svn cruft from an imported project source?
git filter-branch --tree-filter 'rm -rf mydir/to/zap' HEAD
Also see the tip above about zapping .svn cruft.