Viewing Branch Splits and Merges with git log –graph
Running git log --oneline --graph --all draws lines to the left of the commit list, so you can see which commit a branch split from and which merge joined it back. Use this command to check where a working branch diverged before merging, or to see what the history looks like after a merge. I ran the git commands in a test environment and include the output before and after creating the branches, and before and after the merge, exactly as it was printed.
The test environment is Ubuntu 24.04 with Git 2.43.0. The author and committer are example values (Neko <neko@example.com>), and commit dates were set with environment variables. The pager is disabled. The command output was written to a file, so it has no color. I did not check the display on Windows or macOS, or compare it with graphs drawn by GUI tools.
- 1. Creating history where feature/login splits from main
- 2. Adding –graph shows where the branches split
- 3. After a merge, two lines join at one commit
- 4. Showing branch names
- 5. Checking the parents of a merge commit with %p
- 6. Viewing only the main line with –first-parent
- 7. A fast-forward merge does not leave a split line
- 8. Showing unmerged branches with –all
Creating history where feature/login splits from main
I made two commits on main, then created the feature/login branch and made one commit on it. After that I switched back to main and made one more commit. The two branches now continue separately from the "Add top screen" commit.
$ printf "# 猫の手アプリ\n" > README.md && git add . && git commit -q -m "最初のコミット"
$ printf "トップ\n" > top.txt && git add . && git commit -q -m "トップ画面を追加"
$ git switch -q -c feature/login
$ printf "ログイン\n" > login.txt && git add . && git commit -q -m "ログイン画面を追加"
$ git switch -q main
$ printf "# 猫の手アプリ\n猫の写真を集めます。\n" > README.md && git add . && git commit -q -m "READMEに説明を追加"
Adding –graph shows where the branches split
First I listed the commits from all branches without --graph. --all is an option that treats HEAD and all branches and tags as if they had been listed on the command line.
$ git log --oneline --all
323fe3d READMEに説明を追加
4010528 ログイン画面を追加
782b479 トップ画面を追加
e563966 最初のコミット
The four commits appear in a single column, so nothing shows that the "Add login screen" commit belongs to a different branch. Adding --graph gave this output:
$ git log --oneline --graph --all
* 323fe3d READMEに説明を追加
| * 4010528 ログイン画面を追加
|/
* 782b479 トップ画面を追加
* e563966 最初のコミット
* marks one commit, and | is a line that continues downward toward older commits. The "Add login screen" commit is in the second column, and the |/ line below it joins that column back into the first. This means the parent of the second-column commit is the "Add top screen" commit (782b479). So 782b479 is where the two branches split.
If you remove --all, the output includes only the commits reachable from HEAD (currently main). The branch that split off, with the "Add login screen" commit, no longer appears.
$ git log --oneline --graph
* 323fe3d READMEに説明を追加
* 782b479 トップ画面を追加
* e563966 最初のコミット
According to the git log reference, --graph draws the commit history as text in the left part of the output. To draw the graph correctly, it sometimes inserts lines that contain only the graph lines between commits. The |/ lines are these.
After a merge, two lines join at one commit
I made one more commit on feature/login, then merged it into main. main also has commits that feature/login does not have, so the merge cannot be a fast-forward (a merge that only moves the branch pointer forward). It creates a merge commit.
$ git switch -q feature/login
$ printf "ログイン2\n" >> login.txt && git add . && git commit -q -m "ログイン画面の文言を直す"
$ git switch -q main
$ git merge -q -m "Merge branch feature/login" feature/login
This is the list after the merge, without --graph.
$ git log --oneline
6b2554c Merge branch feature/login
7d2ec64 ログイン画面の文言を直す
323fe3d READMEに説明を追加
4010528 ログイン画面を追加
782b479 トップ画面を追加
e563966 最初のコミット
The list is sorted by commit date, so the "Add description to README" commit from main sits between the two feature/login commits. This is the output with --graph:
$ git log --oneline --graph
* 6b2554c Merge branch feature/login
|\
| * 7d2ec64 ログイン画面の文言を直す
| * 4010528 ログイン画面を追加
* | 323fe3d READMEに説明を追加
|/
* 782b479 トップ画面を追加
* e563966 最初のコミット
The |\ line below the merge commit at the top shows one line splitting into two. Read from the top, the lines appear to diverge. Read in time order, the two lines join into one at 6b2554c. The feature/login commits are grouped together in the second column, and the |/ line returns them to 782b479.
The order also changed. Without --graph, the commits from the two branches alternated by date. With --graph, the two feature/login commits appear together. The reference says that if you specify nothing, --graph includes --topo-order. --topo-order shows a commit only after all of its children have been shown, so it does not mix commits from separate lines of development.
Showing branch names
None of the output so far shows which commit is the tip of each branch. Adding --decorate puts branch names after the commits.
$ git log --oneline --graph --decorate
* 6b2554c (HEAD -> main) Merge branch feature/login
|\
| * 7d2ec64 (feature/login) ログイン画面の文言を直す
| * 4010528 ログイン画面を追加
* | 323fe3d READMEに説明を追加
|/
* 782b479 トップ画面を追加
* e563966 最初のコミット
HEAD -> main means you are currently on main, and the tip of main is 6b2554c. feature/login still exists after the merge, and its tip is still 7d2ec64.
When you run the command in a terminal, branch names appear even without --decorate. I connected the output to a terminal with the script command, removed the color codes, and printed the result. The names were the same as with --decorate.
$ script -qec "git log --oneline --graph -3" /dev/null | sed -e "s/\x1b\[[0-9;]*m//g" -e "s/\r\$//"
* 6b2554c (HEAD -> main) Merge branch feature/login
|\
| * 7d2ec64 (feature/login) ログイン画面の文言を直す
| * 4010528 ログイン画面を追加
According to the reference, the default for --decorate is the value of the log.decorate setting, and auto if the setting is not set. auto shows branch names only when the output goes to a terminal. When you pipe the output to another command or write it to a file, add --decorate.
Checking the parents of a merge commit with %p
When the line shapes alone are hard to read, --format with %p lists the abbreviated hashes of each commit's parents. %h is the abbreviated hash of the commit itself.
$ git log --graph --format="%h %p %s"
* 6b2554c 323fe3d 7d2ec64 Merge branch feature/login
|\
| * 7d2ec64 4010528 ログイン画面の文言を直す
| * 4010528 782b479 ログイン画面を追加
* | 323fe3d 782b479 READMEに説明を追加
|/
* 782b479 e563966 トップ画面を追加
* e563966 最初のコミット
The merge commit 6b2554c has two parents, 323fe3d and 7d2ec64. These are the tips of the main side and the feature/login side. Both 4010528 and 323fe3d have 782b479 as their parent. This shows that the |\ and |/ lines in the graph draw the parent-child relationships directly. The first commit has no parent, so the second column is empty.
--format can also include the author and date. %an is the author's name, %ae is the author's email address, and %ad is the author's date. With --date=short, the date is printed only as YYYY-MM-DD. Using this format, I printed the three most recent commits.
$ git log --graph --format="%h %an <%ae> %ad %s" --date=short -3
* 6b2554c Neko <neko@example.com> 2026-11-06 Merge branch feature/login
|\
| * 7d2ec64 Neko <neko@example.com> 2026-11-05 ログイン画面の文言を直す
| * 4010528 Neko <neko@example.com> 2026-11-03 ログイン画面を追加
The list of format placeholders is in the PRETTY FORMATS section of the git log reference.
Viewing only the main line with –first-parent
To see only what has been brought into main, add --first-parent. When the walk reaches a merge commit, this option follows only the first parent.
$ git log --oneline --graph --first-parent
* 6b2554c Merge branch feature/login
* 323fe3d READMEに説明を追加
* 782b479 トップ画面を追加
* e563966 最初のコミット
The two feature/login commits are gone, and only one line remains. The first parent of 6b2554c is 323fe3d, which the %p output above listed first. This is the main side at the time of the merge. The fine-grained commits on the branch are skipped, so the output shows only the sequence: the README was updated, then the login branch was merged.
A fast-forward merge does not leave a split line
If main has not moved ahead since the branch split, the merge is a fast-forward. I created feature/search from main, made one commit on it, then switched back to main and merged it.
$ git switch -q -c feature/search
$ printf "検索\n" > search.txt && git add . && git commit -q -m "検索画面を追加"
$ git switch -q main
$ git merge feature/search
Updating 6b2554c..a804035
Fast-forward
search.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 search.txt
$ git log --oneline --graph --decorate -4
* a804035 (HEAD -> main, feature/search) 検索画面を追加
* 6b2554c Merge branch feature/login
|\
| * 7d2ec64 (feature/login) ログイン画面の文言を直す
| * 4010528 ログイン画面を追加
No merge commit was created, and both main and feature/search point to the same commit, a804035. The graph does not keep any trace that feature/search split off and joined back. Unlike feature/login, the history no longer shows that the commit was made on a separate branch.
According to the git merge reference, --no-ff creates a merge commit even when a fast-forward is possible. Use it when you want the graph to record that work was done on a branch.
Showing unmerged branches with –all
Last, I made one commit on feature/profile without merging it, then made one more commit on main. Without --all, the feature/profile commit does not appear.
$ git log --oneline --graph --decorate
* 5c94d73 (HEAD -> main) トップ画面に猫の写真を追加
* a804035 (feature/search) 検索画面を追加
* 6b2554c Merge branch feature/login
|\
| * 7d2ec64 (feature/login) ログイン画面の文言を直す
| * 4010528 ログイン画面を追加
* | 323fe3d READMEに説明を追加
|/
* 782b479 トップ画面を追加
* e563966 最初のコミット
With --all, you can see that feature/profile splits from a804035 and has not joined any other line yet.
$ git log --oneline --graph --decorate --all
* 5c94d73 (HEAD -> main) トップ画面に猫の写真を追加
| * e5eec21 (feature/profile) プロフィール画面を追加
|/
* a804035 (feature/search) 検索画面を追加
* 6b2554c Merge branch feature/login
|\
| * 7d2ec64 (feature/login) ログイン画面の文言を直す
| * 4010528 ログイン画面を追加
* | 323fe3d READMEに説明を追加
|/
* 782b479 トップ画面を追加
* e563966 最初のコミット
When printed to a terminal, the lines and branch names are colored. The next image shows the same command run with script connected to a terminal, with the colors reproduced.

In this output, the line where feature/profile splits is drawn in red. Below the merge commit, the main-side line is yellow and the feature/login-side line is blue. Each split uses its own color, so you can follow which line leads where.


