Git basics

See the history as a tidy graph

Show your commits and branches as a graph in the terminal with git log, then save it as a short command.

Fill these in once
  1. Show every branch as a graph
    Terminal
    git log --oneline --graph --all

    Each line is one commit with its short ID. The lines and stars on the left show where branches split and joined. Press q to leave.

  2. Show only the last 20 commits
    Terminal
    git log --oneline --graph --all -20
  3. Show the graph for one branch
    Terminal
    git log --oneline --graph main
  4. Save it as a short command
    Terminal
    git config --global alias.tree "log --oneline --graph --all"

    From now on git tree shows the same graph in any repository.

Check it worked

  1. Check the short command works
    Terminal
    git tree -10
Undo it
  1. Remove the short command
    Terminal
    git config --global --unset alias.tree
  1. Show every branch as a graph
    Terminal · Ubuntu / Debian
    git log --oneline --graph --all

    Each line is one commit with its short ID. The lines and stars on the left show where branches split and joined. Press q to leave.

  2. Show only the last 20 commits
    Terminal · Ubuntu / Debian
    git log --oneline --graph --all -20
  3. Show the graph for one branch
    Terminal · Ubuntu / Debian
    git log --oneline --graph main
  4. Save it as a short command
    Terminal · Ubuntu / Debian
    git config --global alias.tree "log --oneline --graph --all"

    From now on git tree shows the same graph in any repository.

Check it worked

  1. Check the short command works
    Terminal · Ubuntu / Debian
    git tree -10
Undo it
  1. Remove the short command
    Terminal · Ubuntu / Debian
    git config --global --unset alias.tree
  1. Show every branch as a graph
    PowerShell
    git log --oneline --graph --all

    Each line is one commit with its short ID. The lines and stars on the left show where branches split and joined. Press q to leave.

  2. Show only the last 20 commits
    PowerShell
    git log --oneline --graph --all -20
  3. Show the graph for one branch
    PowerShell
    git log --oneline --graph main
  4. Save it as a short command
    PowerShell
    git config --global alias.tree "log --oneline --graph --all"

    From now on git tree shows the same graph in any repository.

Check it worked

  1. Check the short command works
    PowerShell
    git tree -10
Undo it
  1. Remove the short command
    PowerShell
    git config --global --unset alias.tree

New to branch? I explain it in plain English on Layman Terms.