Getting smarter with git

I generally do all my work with git on the command line — sometimes I do commits in my IDE but all my pushes, pulls, merges, and looking at history is done on the command line.

First off, I have a command prompt that tells me what branch I’m in. I use zsh but you should be able to find a similar one if you use bash. I will warn you that it’s really slow in Cygwin but in “pure” Unix systems like OSX and Ubuntu it works fine.

After that, I really only have 4 magic git commands:

The git smart-* commands are from the git-smart Ruby gem. You can read all about it here. These commands have helped me become more productive and save me so much time.

Getting status

My gss command is one that I run the most often. It’s my default look into what has changed locally. It’s a quick view, and it tells me what I need, short and sweet:


Looking at Commit Logs

I use gl as my lifesaver on what has changed and when. My favorite part is how it tells you what was committed in each branch and the life-cycle of branches. And you can easily see when branching and merging went really, really wrong.


Yes, that’s a real log from a real git project I was in a long time ago. And, yes, it was my fault.

Another great thing about gl is that it tells you what remote that was pushed to. So if you have deployed something and can’t figure out why you don’t see the changes, then it’s easy to see if you forgot to push your changes. This has saved my sanity many time.

Merging and Pulling

gm is a magic little command that does a lot of heavy lifting:

  1. If you have unstaged changes it stashes them
  2. Does a non-fast forward merge with the given branch. If none is given, it uses master. Non-fast forward is important because it logs where the merge was.
  3. Pop the stash, if necessary
  4. Gives you some stats back

gup is similar, only it tries to pull from the tracking branch. It does the stash as well, if necessary. If all else fails, it will try a rebase to make the merge, which doesn’t happen often (and, to me, is a sign that something went seriously wrong).

So, there are some every day tricks that I use to make my work with git a lot easier.

Leave a Reply

Your email address will not be published. Required fields are marked *