Learning Objectives
By the end of this lesson you will be able to:
- Read the ASCII graph Git draws and identify branches and merges in it
- Build a log command that shows dates, authors and branch labels usefully
- Find which merge brought a given commit into
main - Use the graph to answer "what is in this build?" precisely
The Command Worth Aliasing
git log --graph --oneline --decorate --all
Four flags, and each one earns its place:
| Flag | What it adds |
|---|---|
--graph |
The ASCII lines showing the branch structure |
--oneline |
One commit per line instead of six |
--decorate |
Branch and tag labels next to the commits they point at |
--all |
Every branch, not just the one you're on |
That last one matters more than it looks. Without --all you only see the ancestry of your current branch, which quietly hides everything you were probably trying to look at.
Because you will type this constantly, alias it once:
git config --global alias.lg "log --graph --oneline --decorate --all"
Then it is just git lg.
Reading the Shape
* 9a1b2c3 (HEAD -> main) Merge branch 'feature/auth-test'
|\
| * d4e5f6a (feature/auth-test) Add negative cases for expired token
| * c3d4e5f Add auth test fixtures
* | b2c3d4e Fix session timeout calculation
* | a1b2c3d Update dependency versions
|/
* 8f3c2a1 (tag: v2.4.0) Add password reset endpoint
Read it bottom-up — that is chronological order.
8f3c2a1is where the two lines split. It carries the tagv2.4.0.- The left column continued as
main: two commits,a1b2c3dandb2c3d4e. - The right column is
feature/auth-test: two commits,c3d4e5fandd4e5f6a. |\at the top marks a commit with two parents — the merge commit.9a1b2c3is that merge, andHEAD -> mainsays it is where you are standing.
Once you can see that shape, you can answer "what did this merge bring in?" by reading the right-hand column.
Useful Variations
git log --graph --oneline --merges
Only the merge commits. On a --no-ff team, this is a list of every feature that has landed — the most compact release summary available.
git log --graph --pretty=format:"%h %ad %an %s" --date=short --all
Adds the date and author to each line, which is what you want when you are building a timeline of when something broke.
git log --graph --oneline v2.4.0..HEAD
Everything since the last release tag. When someone asks "what's in this build?", this is the answer — and it comes with the branch structure attached.
git log --oneline --graph --first-parent main
Follows only the first parent of each merge, which on main means "one line per feature that landed" rather than every individual commit inside them. A very good high-level view.
Finding Where a Commit Landed
You have a commit ID from a bug report and want to know which merge brought it into main:
git log --merges --oneline --ancestry-path d4e5f6a..main
The last line of that output is the merge commit that first carried d4e5f6a into main. From there, git show <merge-id> tells you the branch name and everything else that arrived with it.
Also useful, and much simpler:
git branch --contains d4e5f6a
git tag --contains d4e5f6a
"Which branches have this commit?" and "which releases shipped it?" — two questions QA asks constantly, answered directly.
Pro Tip: Graphical clients (GitKraken, the history view in your IDE, the Network graph on GitHub) draw the same information with colours and curves. Use them. The ASCII version is what is always available, on any machine, over SSH, with no setup — which is why it is worth being able to read.
Key Takeaways
git log --graph --oneline --decorate --allis the everyday graph command; alias it- Read the graph bottom-up;
|\marks a merge commit's two parents --decoratelabels which commits the branches and tags point at--mergesalone gives a compact list of everything that has landedv2.4.0..HEADscopes the log to a single build or releasegit branch --containsandgit tag --containsanswer "where did this commit end up?"