Display readable Git branch graphs

Draw commit topology in the terminal, add a useful alias, and filter the graph without accidentally retaining every reference.

Best practices
Illustration of Git branches and version history

Use git log --graph --oneline --all --decorate for a compact terminal view of commit ancestry. The graph shows parent relationships; branch and tag decorations identify refs pointing at commits now, not a permanent record of every historical branch name.

Start with the standard graph

git log --graph --oneline --all --decorate

--graph draws ancestry lines, --oneline condenses each commit, and --decorate shows ref labels. --all adds the refs available in the repository and HEAD as traversal starting points. It does not fetch new remote history or include every unreachable commit object.

Create a repository-local alias if you use the view often:

git config --local alias.lg 'log --graph --oneline --all --decorate'
git lg

Use --global instead only if you want that alias in your other repositories too.

Add author and time information

git log --graph --all --decorate \
  --format='%C(auto)%h %d%Creset %s %Cgreen(%ar)%Creset %Cblue<%an>%Creset'

The format includes an abbreviated ID, decorations, subject, relative author date, and author name. Author and committer dates can differ. Color rendering depends on output destination and configuration; omit color placeholders for a plain-text report.

Narrow the view

git lg --max-count=30
git lg --since='2 weeks ago'
# Use a command without --all to restrict traversal to these starting refs:
git log --graph --oneline --decorate main feature-x

Adding main feature-x to an alias that already includes --all does not cancel --all. Date and path filters can also hide ancestry details, so a filtered graph is not always a complete representation of the repository. --since uses commit-date filtering, while %ar displays the author date in the example above.

Interactive tools and documentation

Git Graph or GitLens in VS Code, JetBrains' Git log view, GitKraken, and Sourcetree offer interactive ways to inspect commits and diffs. Check current availability, licensing, and repository support before choosing a tool. gitk is another graph viewer, but its installation and GUI dependencies vary by Git distribution; it is not guaranteed to be present.

For documentation, a screenshot can capture an actual history view. A Mermaid gitGraph diagram can explain a simplified workflow, but it is a manually authored illustration unless generated from verified history. Label it accordingly rather than presenting an invented topology as repository evidence.

If an old rebased or detached commit is missing, inspect git reflog and the relevant refs. Reflog entries and unreachable objects can expire; an ordinary --all graph does not establish whether such an object has already been removed.

See git-log graph and formatting options, Git aliases, and gitk.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting