Cleaner Git logs and Git aliases

If you spend any time during your day reading Git logs, you probably hate having to page through the log to see a specific commit. Here’s a couple of nice git log options to help you quickly glance at your commit history.

--abbrev-commit abbreviates the commit SHA to just 6 or 7 unique characters.
--pretty=oneline prints only one line of your commit message. This is especially useful if you follow the convention of writing descriptive subject lines for your commits. This lets you page through many lines of commits and know exactly how your project progressed. Here is a nice guide for writing good commit messages.

Git aliases

If you find yourself using these two git log options frequently, you might want to consider aliasing them. A Git alias allows you to create a ‘shortcut’ command. The code below creates a permanent global change to my Git configuration. So that I can write git cleanlog instead of git log --abbrev-commit --pretty=oneline.

git config --global alias.cleanlog 'log --abbrev-commit --pretty=oneline'

Another Git command that I aliased was the reset command to remove files from the index. To me, writing git unstage seemed to be a sensical command to type when I want to unstage files.

git config --global alias.unstage 'reset HEAD -- '

If you feel like aliasing is the way to go, start thinking about the Git commands you use on a daily basis and start creating your own aliases. You might want to start simple, like checkout and then add more options as you find yourself using more complex flow control commands.

EDIT: Mar 10, 2016

I find myself using a few more really simple, but useful Git aliases nowadays.

git config --global alias.commit 'commit -v'
git config --global alias.s 'status -s'

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s