This post is part of an ongoing series on dotfiles. In today’s episode we look at dotfiles for Git.

rerere

The first item I’d like to call attention to is a little known option called “reuse recorded resolution”, or rerere for short. It’s a feature which allows Git to remember how you resolved a particular merge conflict, letting it replay and reuse that resolution if it encounters the same conflict again. This is especially useful to keep re-integration merges from littering up your history in a feature branch.

The official Git blog has a good post on how and when to use rerere. The easiest way to enable it by setting rerere.enabled globally.

Aliases

I’ve also got a few handy git aliases defined. While you can find the full config here, the following ones I believe to be worthy of special attention:

[alias]

# Show commits in upstream which aren't yet merged in
# your local branch
behind = log --graph --pretty=format:'%C(yellow)%h%Creset %C(yellow)%d%Creset %s %C(bold blue)(%an, %cr)%Creset' --abbrev-commit --date=relative ..@{u}

# And the opposite, commits in local branch which aren't
# yet pushed upstream
ahead = log --graph --pretty=format:'%C(yellow)%h%Creset %C(yellow)%d%Creset %s %C(bold blue)(%an, %cr)%Creset' --abbrev-commit --date=relative @{u}..

# See what new commits have been created by the last command.
# Mainly useful to see commits pulled in by a git pull or merge
# of another branch.
new = "!sh -c 'git log --graph --pretty=format:\"%C(yellow)%h%Creset %C(yellow)%d%Creset %s %C(bold blue)(%an, %cr)%Creset\" --abbrev-commit --date=relative $1@{1}..$1@{0} \"$@\"'"