Git is great.  You should start using it immediately (if not sooner!)  In this new “Git Tips & Tricks” series, I’m not going to talk about the basic git operations that have already been covered by more talented people than me.  Instead, I’m going to show you all the Git commands and scripts I use day-to-day.  Let’s start by making sure you are using the correct tools.

[more]

Git is as big a step up from Subversion as Subversion was from Visual SourceSafe.  But, as one of my friends aptly put it users ago, “With great  power comes great pain in the ass.”   Git has a learning curve to it.  Well, it’s a curve in the same sense that this is a hill:

image

Choosing the right tools makes a world of difference though.  Here’s what I use:

Git Extensions – I use this for browsing the repo, performing my commits, and searching through history.  I also use this to solve conflicts during a merge or rebase.

Powershell + posh-git – I use this combination for everything else: cloning, branching, pushing, pulling, initiating a rebase, etc. 

I have my Powershell profile synchronized across my various computers via Dropbox.  I also keep my standard settings for git in my Powershell profile, ensuring that my git environment is configured the same on all of my machines.  Here are the settings I use:

#Make sure the SSH agent is running.
Start-SshAgent -Quiet

#Checkout as-is, commit as-is.  Failure to do this will cause you pain and suffering. 
git config --global core.autocrlf false
#By default, new branches should rebase when you do a pull instead of a merge.
git config --global branch.autosetuprebase always
#I use cherry-pick a lot, and this saves me a few keystrokes
git config --global alias.cp cherry-pick

#You want the following settings if you are using Git as your SVN client, which you should definitely do if you are stuck with SVN.

#SVN-delete empty directories when you remove the last file from the directory using git.
git config --global svn.rmdir true
#The whole dcommit thing never sounded right to me, so I aliased it to 'spush', for 'svn-push'
git config --global alias.spush "svn dcommit --rmdir"
git config --global alias.spull "svn rebase"
git config --global alias.sfetch "svn fetch"

Tools to Avoid

I recommend that you avoid TortoiseGit.  All it will do is strengthen bad habits you picked up from Subversion.  I also don’t like Github for Windows.  It’s pretty, sure, but it does some goofy stuff by trying to abstract important parts of Git.  For example, there is no “sync” operation in Git.  I’m not sure why the Github team thought it was a good idea to try and implement one.  All I’ve ever seen it do is cause problems.   Git Extensions, by contrast, will show you what it’s passing through to git.exe, so you can learn the command line while using the GUI.