BEGINNERGITALIASES

Beautiful One-Line git log as a Global Alias

Set up a global git alias for a colored, graph-aware, one-line git log that makes commit history actually readable.

By Tested on git 2.43+
Published Jun 9, 2026

A global git alias that turns the unreadable default git log into a colored, graph-aware, one-line view of every branch. Configure it once in ~/.gitconfig and git lg works in every repo on your machine. This is the first git config I set up on any new dev machine.

Tested on git 2.43+.

When to Use This

  • Quickly scanning commit history during code review
  • Visualizing how branches diverged before a rebase or merge
  • Showing newcomers what your branching model actually looks like
  • Replacing the verbose default git log with something readable

Don't use this when you need full commit messages or diffs (use plain git log or git show) or when piping to another command that expects machine-parseable output.

Code

Set the alias globally:

git config --global alias.lg "log --graph --abbrev-commit --decorate \
--format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) \
%C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all"

Or edit ~/.gitconfig directly:

[alias]
    lg = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all

Now git lg produces something like:

* a1b2c3d - (2 hours ago) feat: add login form - Rabi (HEAD -> feature/login)
* e4f5g6h - (3 hours ago) fix: typo in label - Rabi
* i7j8k9l - (1 day ago) feat: scaffold login - Rabi
| * m0n1o2p - (2 days ago) docs: update readme - Teammate (origin/main, main)
|/
* q3r4s5t - (3 days ago) initial commit - Rabi

Branches, merges, and authorship are all visible at a glance.

Usage

A few related aliases I keep next to it:

[alias]
    # Pretty graph log of all branches
    lg = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all
 
    # Just the current branch
    lgo = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)'
 
    # Last 10 commits, one line each
    last = log -10 --oneline --decorate
 
    # What changed in the last commit
    show-last = show --stat HEAD
 
    # Branches sorted by most recent activity
    recent = for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)' refs/heads/

git last shows the 10 most recent commits. git recent lists every local branch sorted by last commit date — perfect for seeing what you were working on a week ago.

Pitfalls

  • Long alias values are hard to escape on the command line. Edit ~/.gitconfig directly with a text editor instead of trying to quote the whole thing in git config.
  • The format string is git's syntax, not printf. %h is short hash, %s is subject line, %an is author name, %ar is relative date. Full reference in git help log.
  • --all shows every ref, including remote tracking branches. That's what you want for a full picture, but it can be noisy in repos with hundreds of stale branches.
  • %C(auto) resets coloring per token. Without it, the color of the previous token bleeds through and the output looks messy.
  • Pipe to less for huge histories. git lg | less -R preserves colors. Without -R, you get raw ANSI escape codes.
  • The alias does not survive a git config reset. Back up ~/.gitconfig before running git config --global --unset operations.

Frequently Asked Questions

What does git log --graph actually show?

It draws an ASCII art graph of the commit DAG (directed acyclic graph), showing branches, merges, and parent relationships. Combined with --oneline and --all, you get a complete visual history of every branch and tag in your repo, condensed to one line per commit.

Why use a git alias instead of a shell alias?

Git aliases work everywhere git works — inside scripts, on CI runners, on remote machines via SSH. Shell aliases only work in your local interactive shell. A git alias also auto-completes after `git ` and shows up in `git --help`.

X (Twitter)LinkedIn