Skip to content

Instantly share code, notes, and snippets.

@mlgarchery
Last active April 11, 2025 13:19
Show Gist options
  • Save mlgarchery/6aad6ce24fdced2f803545741f2e71d4 to your computer and use it in GitHub Desktop.
Save mlgarchery/6aad6ce24fdced2f803545741f2e71d4 to your computer and use it in GitHub Desktop.
Better git aliases for `git log` and `git branch`

When you merge branches, you can be confused by the output git log gives you sometimes. The main issue is that by default git log use chronological order and not topological order --topo-order, which is the order of the commits when they appeared on their respective branch. This is disturbing to me. Look at it by youself:

image

The idea is to replace your daily use of git log with git l that use the --topo-order option.

git l

With colors and a nice column display

image

git lg and git lga

Give a better historical display. They use the option --graph which respect the topological order by default. image

With all references (not the most useful but can help sometimes) image

git b

List your branch by date in reverse order

image

Here are the lines to add to your .gitconfig:

[alias]


  l = log --topo-order --format='%<(50,trunc)%s %<(11,trunc)%C(green)%an %<(14,trunc)%C(cyan)%cr %C(reset)%h'
  lg = log --graph --format='%<(50,trunc)%s %<(11,trunc)%C(green)%an %<(14,trunc)%C(cyan)%cr %C(reset)%h %C(yellow)%d'
  lga = log --graph --format='%<(50,trunc)%s %<(11,trunc)%C(green)%an %<(14,trunc)%C(cyan)%cr %C(reset)%h %C(yellow)%d' --all
  b = for-each-ref --sort=committerdate refs/heads/ --format='%(color: cyan)%(committerdate:relative) %(color: yellow)%(refname:short)'
  # you might also like:
  s = status
  co = checkout
  fp = push --force-with-lease

I hope this is useful to some of you out there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment