Git gives you as much flexibility in how you construct your VCS workflow as it does for the commands you use on your local repo. In your gitconfig file you can add alises for your favourite commands, in this article I'll talk about mine. You can see my gitconfig on github.

git standup

alias for git log ––since yesterday ––author joe ––all

Just about to head to a standup but you can't remember everything that you did yesterday? This command will come to your rescue. It only lists what you did in the last 24 hours.

3400455 - fixed the whizzbang (Mon, 1 Apr 2013 13:57:37 +0100) <Joe Wright>
5dae0a0 - whizzbang feature (Mon, 1 Apr 2013 13:57:32 +0100) <Joe Wright>

git purr

alias for git pull ––rebase

In Git you have public and private branches, public branches are the ones on github (or your own git host), private branches are in your local git repo and are setup to be tracking or topic. A tracking branch is linked to a public branch and a topic is only in your local git repo.

You have two options when you want to integrate changes between branches, either you merge or rebase. By default when you do a pull on a tracked branch it performs a fetch then a merge. If you've made changes locally and someone else has pushed changes to your git host then git will automatically merge these together with a merge commit.

4ffe733 - Merge branch 'development' of into master

On an active project with other colleagues using pull will generate a load of these noisy commits in your projects history. I only like merge commits to be in the history when a topic branch has been reintegrated. Tracking branches should have a linear history.

When you do a git pull ––rebase, git fetches the changes from your remote repo and then perform a rebase rather than the default merge. A rebase resets the HEAD of your local branch to be the same as the remote HEAD, then replays your local commits back into repo. This means you don't get any noisy merge messages in your history. As well as giving a linear history, this also helps when using bisect.

git st

alias for git status -sb

Git gives a verbose output when you perform a status which is excellent when you are getting started with git. As you become used to the output you want a shorter version. The output of this alias shows a single letter that represents the change type and reports how far ahead of the remote branch you are.

## master...origin/master [ahead 2]
A  g
D  gitignore

git ready

alias for git rebase -i @{u}

Once you've committed a few local changes you'll want to share them with your team by pushing to your git host. Before I push I always run the git ready alias to see what's going to be pushed so I can reword commit messages and squash related commits together. git ready performs an interactive rebase on your unpushed commits.

Let's say I've pushed two commits that are related to a new feature and I have another where I made a spelling mistake in the commit message. When I run git ready I get dropped into vim with this input.

pick 7f06d36 whizzbang feature - adding fizzbuzz
pick ad544d0 whizzbang feature - minor refactoring to fizzbuzz
pick de3083a spelling mizzztake

I want to squash the two whizzbang feature commits together. So I change pick to say s to squash the two together into a single commit. I also want to reword the commit with the spelling mistake. To do this I make the file look like:

pick 7f06d36 whizzbang feature - adding fizzbuzz
s ad544d0 whizzbang feature - minor refactoring to fizzbuzz
r de3083a spelling mizzztake<br />

This gives me two new commit messages to edit, which I update. Now when I push the remote repo host receives two commits

3400455 - spelling mistake
5dae0a0 - whizzbang feature

git lg

alias for git log ––pretty=format:'%Cred%h%Creset -%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'

When I'm viewing history I just want to see the SHA, the commit message, who made the commit and how long ago. This custom log output gives me:

3400455 - spelling mistake (20 minutes ago) <Joe Wright>
5dae0a0 - whizzbang feature (28 minutes ago) <Joe Wright>
efaea80 - Removing trailing space on save (4 days ago) <Another Person>
c351700 - Copying to system clipboard in vim (5 days ago) <Joe Wright>

I'd be interested to hear about your favourite git aliases too.