Learning git made me a better svn user

Before learning git, I rarely created branches in svn projects. Honestly, I don’t know why. It seemed like too much work, but really that was just because I didn’t do it. Now, whenever I start a new feature, I create a branch first.

svn cp {{trunk}} {{branches/blah}}

Sure, it creates a branch on the svn server that may or may not go anywhere, but it’s simple to remove it, so there’s no harm. It also feels a lot safer. Even my experimental code lives on both my system and on the repository server. My commits are getting smaller and more focused as well. Previously, I would often wait until a whole feature was complete before committing. Now, I commit each individual step.

When I’m done, it’s simple to merge back in.

svn merge -r{{start_rev}}:{{end_rev}} {{branches/blah}}

But what about conflicts, right? Git handles merging much better, but again, it’s an unfounded fear. Yes, if changes are made to trunk while you are working on the branch, you might get conflicts, but in my experience, conflicts are rare and the benefits of branching outweigh the risk.

My .gitconfig

Here’s my current .gitconfig file. It’s very simple, but it makes using git so much better. git s is a simplified git status, and git l is a log that shows one-line commit messages and a tree that shows where branches and merges were made.

   ui = true 
   s = status -su 
   l = log --graph --pretty=format:'%C(yellow)%h%C(cyan)%d%Creset %s %C(white)- %an, %ar%Creset'

I also highly recommend you check out the table below, which I’ve copied from the bottom of the 10 things I hate about git post. It helps make sense of some common commands that I thought were useless as well. Adding the switches Steve Bennett recommends clears things up a bit.

Base commandUseless functionalityUseful commandUseful functionality
git branch fooCreates a branch but does nothing with itgit checkout -b fooCreates branch and switches to it
git remoteShows names of remotesgit remote -vShows names and URLs of remotes
git stashStores modifications to tracked files, then rolls them backgit stash -uAlso does the same to untracked files
git branchLists names of local branchesgit branch -rvLists local and remote tracking branches; shows latest commit message
git rebaseDestroy history blindfoldedgit rebase -iLets you rewrite the upstream history of a branch, choosing which commits to keep, squash, or ditch.
git reset fooUnstages filesgit reset –hard
git reset –soft
Discards local modifications
Returns to another commit, but doesn’t touch working directory.
git addNothing – prints warninggit add .
git add -A
Stages all local modifications/additions
Stages all local modifications/additions/deletions