Getting started with Git


I’ve recently started using Git, which I’ve found I much prefer to Subversion for two reasons. The first is that it’s really fast since almost all commands are run locally. The second reason is that Subversion litters your source code with .svn directories and should you accidentally delete or move one then you’re in for a world of hurt. Git also handles ignored files in a much easier manner.

There are two downsides with Git. The first is that there’s no central server to store the code base. GitHub or BitBucket can fulfill this role if you don’t mind someone else hosting your source code. If you want to set up a central server yourself it seems the best solution is gitolite. The documentation isn’t for beginners, but I found a decent tutorial on setting up gitolite.

The other downside with git is that the commands can be a bit bizarre.

git aliases

You can set aliases using git config --global.  E.g. git config --global alias.dt "difftool --no-prompt" makes git dt act the same as git difftool --no-prompt. These aliases are saved in ~/.gitconfig. My ~/.gitconfig looks like:

	name = Ben McCann
	email =
	cam = commit -am
	dt = difftool --no-prompt
	dtm = !meld .
	pending = !clear & git status
	rev = checkout --
	revall = reset --hard HEAD
	default = current

Reverting to a previous version

$ git reset --hard YOUR_CHANGESET_HERE
$ git reset --soft @{1}
$ git commit -a
Be Sociable, Share!