Jun 23, 2015

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:

git-status

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.

when_branches_go_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.

About the Author

Object Partners profile.
Leave a Reply

Your email address will not be published.

Related Blog Posts
Natively Compiled Java on Google App Engine
Google App Engine is a platform-as-a-service product that is marketed as a way to get your applications into the cloud without necessarily knowing all of the infrastructure bits and pieces to do so. Google App […]
Building Better Data Visualization Experiences: Part 2 of 2
If you don't have a Ph.D. in data science, the raw data might be difficult to comprehend. This is where data visualization comes in.
Unleashing Feature Flags onto Kafka Consumers
Feature flags are a tool to strategically enable or disable functionality at runtime. They are often used to drive different user experiences but can also be useful in real-time data systems. In this post, we’ll […]
A security model for developers
Software security is more important than ever, but developing secure applications is more confusing than ever. TLS, mTLS, RBAC, SAML, OAUTH, OWASP, GDPR, SASL, RSA, JWT, cookie, attack vector, DDoS, firewall, VPN, security groups, exploit, […]