small useful git tricks

- 1 min read

Here’s a couple of git aliases I use all the time. It gives you a quick and clear overview of your branches and commits. It can even watch for changes in realtime and show you any changes.

git log screenshot

A better git log

Add this to your .gitconfig:

1
2
[alias]
    tree = log --graph --decorate --all --format='%C(auto)%h%d %Creset%s %C(dim)(%an)%Creset'

Run git tree and you get a compact view of your commit history with branches, colored hashes, commit messages, and authors. The --all flag shows all branches, not just the current one.

Live-updating git log

This one needs viddy, which is like watch but better. Install it with brew install viddy on Mac or go install github.com/sachaos/viddy@latest if you have Go.

1
2
[alias]
    watch-tree = !viddy -n 1 -d 'git -c color.ui=always tree | head -n $(tput lines)'

Run git watch-tree and you get a live view that updates every second. The head -n $(tput lines) part limits the output to your terminal height so it doesn’t scroll. The -c color.ui=always keeps the colors when piping through viddy.

I keep this running in a terminal while I work. When I commit or switch branches, the view updates automatically.