Compare Two Git Branches with git log –left-right
After two branches diverge, you can see which commits each one has added with a single command: git log --left-right main...feature/search. Commits that exist on only one side are listed, with < for commits on the left side (main) and > for commits on the right side (feature/search). Use it before opening a pull request or merging, when you want to check the difference between branches or how many commits each is ahead and behind. I ran the git commands in a test environment and include the output with and without --left-right as it was.
The test environment was Ubuntu 24.04 with Git 2.43.0. The author name and email were example values (Neko <neko@example.com>), and the commit dates were set with environment variables. The pager was disabled. I did not test on Windows or macOS, or the branch comparison screens of services such as GitHub.
- 1. Create two diverged branches for testing
- 2. Without –left-right, view each side with two commands
- 3. Add –left-right to see < and > for each branch
- 4. Show only one branch's commits
- 5. Identify commits brought in with cherry-pick
- 6. With –graph, < and > appear at the commit positions in the graph
- 7. Count how far ahead and behind
- 8. Compare with the upstream branch
Create two diverged branches for testing
I made two commits on main, created the feature/search branch, and then added commits to both branches.
- Two commits on
feature/search: "Add search screen" and "Add narrowing to search" - Two commits on
main: "Add usage heading to README" and "Add password field to login screen" - Two more commits on
feature/search: one that brings in themaincommit "Add password field to login screen" withgit cherry-pick, and "Add sorting to search results"
A commit brought in with cherry-pick has the same content changes as the one on main, but it is a different commit (the hash is different). I included it so I could check how to tell these apart in a later section.
Without –left-right, view each side with two commands
To see the difference between two branches without --left-right, run a two-dot range (A..B) twice, with the direction reversed. main..feature/search shows the commits that are on feature/search but not on main.
$ git log --oneline main..feature/search
f8027dc 検索結果の並び替えを追加
a07d676 ログイン画面にパスワード欄を追加
96a7a06 検索に絞り込みを追加
483bc38 検索画面を追加
$ git log --oneline feature/search..main
3692910 ログイン画面にパスワード欄を追加
c0131cd READMEに使い方の見出しを追加
With a three-dot range (A...B), the commits from both branches are shown in one command. However, the output alone does not tell you which branch each commit belongs to.
$ git log --oneline main...feature/search
f8027dc 検索結果の並び替えを追加
a07d676 ログイン画面にパスワード欄を追加
3692910 ログイン画面にパスワード欄を追加
c0131cd READMEに使い方の見出しを追加
96a7a06 検索に絞り込みを追加
483bc38 検索画面を追加
The official reference on revision specification (gitrevisions) describes r1...r2 as the symmetric difference: the set of commits that are reachable from one of r1 (the left side) or r2 (the right side), but not from both. It does not include the commit where the two branches diverged (the merge base), or the shared commits before it.
Add –left-right to see < and > for each branch
I added --left-right to the same three-dot range.
$ git log --oneline --left-right main...feature/search
> f8027dc 検索結果の並び替えを追加
> a07d676 ログイン画面にパスワード欄を追加
< 3692910 ログイン画面にパスワード欄を追加
< c0131cd READMEに使い方の見出しを追加
> 96a7a06 検索に絞り込みを追加
> 483bc38 検索画面を追加
< marks commits that exist only on main, which is written on the left of .... > marks commits that exist only on feature/search, which is written on the right. The git log reference also says that commits reachable from the left side are marked <, and commits reachable from the right side are marked >. The order stays the same as without the option, newest first, so commits from both branches are interleaved by date.
< and > are determined by the position where the branch is written, not by the branch name. When I swapped the left and right sides, the symbols swapped too.
$ git log --oneline --left-right feature/search...main
< f8027dc 検索結果の並び替えを追加
< a07d676 ログイン画面にパスワード欄を追加
> 3692910 ログイン画面にパスワード欄を追加
> c0131cd READMEに使い方の見出しを追加
< 96a7a06 検索に絞り込みを追加
< 483bc38 検索画面を追加
In the normal output without --oneline, the symbol appears between commit and the hash. Only the first 11 lines are shown.
$ git log --left-right main...feature/search | head -n 11
commit > f8027dcbd20b0a1d2cbf0654b69463a7b578e3b2
Author: Neko <neko@example.com>
Date: Sun Nov 8 10:00:00 2026 +0900
検索結果の並び替えを追加
commit > a07d676afd875ab9aa0782ed4d3ce07918f5cf2f
Author: Neko <neko@example.com>
Date: Fri Nov 6 10:00:00 2026 +0900
ログイン画面にパスワード欄を追加
When you set the layout with --format, the symbol appears where you write %m. I also included the date.
$ git log --left-right --format="%m %h %ad %s" --date=short main...feature/search
> f8027dc 2026-11-08 検索結果の並び替えを追加
> a07d676 2026-11-06 ログイン画面にパスワード欄を追加
< 3692910 2026-11-06 ログイン画面にパスワード欄を追加
< c0131cd 2026-11-05 READMEに使い方の見出しを追加
> 96a7a06 2026-11-04 検索に絞り込みを追加
> 483bc38 2026-11-03 検索画面を追加
Adding --left-right to the two-dot range (main..feature/search) does not cause an error. However, only commits from the feature/search side are output, so all of them are marked >. To compare both sides, use the three-dot range.
$ git log --oneline --left-right main..feature/search
> f8027dc 検索結果の並び替えを追加
> a07d676 ログイン画面にパスワード欄を追加
> 96a7a06 検索に絞り込みを追加
> 483bc38 検索画面を追加
Show only one branch's commits
--left-only outputs only the commits marked <, and --right-only outputs only the commits marked >. The results were the same as running the two-dot ranges with reversed direction.
$ git log --oneline --left-only main...feature/search
3692910 ログイン画面にパスワード欄を追加
c0131cd READMEに使い方の見出しを追加
$ git log --oneline --right-only main...feature/search
f8027dc 検索結果の並び替えを追加
a07d676 ログイン画面にパスワード欄を追加
96a7a06 検索に絞り込みを追加
483bc38 検索画面を追加
Identify commits brought in with cherry-pick
In the output with --left-right, "Add password field to login screen" appears with both < and >. It is a main commit that I cherry-picked onto feature/search, so the content changes are the same. When you add --cherry-mark, commits that have an equivalent change on the other branch are shown with = instead of < or >.
$ git log --oneline --left-right --cherry-mark main...feature/search
> f8027dc 検索結果の並び替えを追加
= a07d676 ログイン画面にパスワード欄を追加
= 3692910 ログイン画面にパスワード欄を追加
< c0131cd READMEに使い方の見出しを追加
> 96a7a06 検索に絞り込みを追加
> 483bc38 検索画面を追加
If you use --cherry-pick instead of --cherry-mark, the pairs of commits with the same change are removed from the output. Only the changes that exist on just one branch remain.
$ git log --oneline --left-right --cherry-pick main...feature/search
> f8027dc 検索結果の並び替えを追加
< c0131cd READMEに使い方の見出しを追加
> 96a7a06 検索に絞り込みを追加
> 483bc38 検索画面を追加
According to the reference, --cherry has the same meaning as --right-only --cherry-mark --no-merges. It outputs only the commits on the right-side branch. Commits that have an equivalent change on the left side are marked =, and the others are marked +. Use it to check which commits on your branch are already in main.
$ git log --oneline --cherry main...feature/search
+ f8027dc 検索結果の並び替えを追加
= a07d676 ログイン画面にパスワード欄を追加
+ 96a7a06 検索に絞り込みを追加
+ 483bc38 検索画面を追加
With –graph, < and > appear at the commit positions in the graph
When combined with --graph, which draws the commit history as a text diagram, < and > appear at the positions where the commits are drawn. The order is also grouped by branch instead of by date. According to the reference, --graph changes the default to --topo-order (a order that lists children before parents and does not mix commits from separate lines of history).
$ git log --oneline --graph --left-right main...feature/search
> f8027dc 検索結果の並び替えを追加
> a07d676 ログイン画面にパスワード欄を追加
> 96a7a06 検索に絞り込みを追加
> 483bc38 検索画面を追加
< 3692910 ログイン画面にパスワード欄を追加
< c0131cd READMEに使い方の見出しを追加
With this output alone, the two branches look like a single line. Adding --boundary also shows the commit at the divergence point outside the range (here, "Add login screen"), and the diagram made it clear that the history splits into two lines from there. The divergence point commit is marked with o.
$ git log --oneline --graph --left-right --boundary main...feature/search
> f8027dc 検索結果の並び替えを追加
> a07d676 ログイン画面にパスワード欄を追加
> 96a7a06 検索に絞り込みを追加
> 483bc38 検索画面を追加
| < 3692910 ログイン画面にパスワード欄を追加
| < c0131cd READMEに使い方の見出しを追加
|/
o f20c99c ログイン画面を追加
When --boundary is added without --graph, the divergence point commit is marked with -. This is the same symbol described for --left-right in the reference.
$ git log --oneline --left-right --boundary main...feature/search
> f8027dc 検索結果の並び替えを追加
> a07d676 ログイン画面にパスワード欄を追加
< 3692910 ログイン画面にパスワード欄を追加
< c0131cd READMEに使い方の見出しを追加
> 96a7a06 検索に絞り込みを追加
> 483bc38 検索画面を追加
- f20c99c ログイン画面を追加
Count how far ahead and behind
If you want only the counts, not the list of commits, use git rev-list with --left-right --count. It outputs the number of left-side and right-side commits, separated by a tab. There are 2 commits only on main and 4 commits only on feature/search.
$ git rev-list --left-right --count main...feature/search
2 4
Adding --cherry-mark as well outputs the counts with the equivalent-change pairs excluded (1 and 3), followed by a third number for the equivalent-change commits (2, one on each branch). This matches the description of --count in the git rev-list reference.
$ git rev-list --left-right --count --cherry-mark main...feature/search
1 3 2
Compare with the upstream branch
In this test, I did not use a remote. Instead, I set the local main as the upstream branch of feature/search. Then I wrote @{upstream}...HEAD, which gave the same result as main...feature/search. @{upstream} can be abbreviated as @{u}. If you omit the right side of ..., it is treated as HEAD, so @{u}... alone gives the same result.
$ git switch -q feature/search && git branch -q --set-upstream-to=main
$ git log --oneline --left-right @{u}...
> f8027dc 検索結果の並び替えを追加
> a07d676 ログイン画面にパスワード欄を追加
< 3692910 ログイン画面にパスワード欄を追加
< c0131cd READMEに使い方の見出しを追加
> 96a7a06 検索に絞り込みを追加
> 483bc38 検索画面を追加
The "ahead 4, behind 2" shown on the first line of git status -sb matches the 4 commits marked > and the 2 commits marked <.
$ git status -sb | head -n 1
## feature/search...main [ahead 4, behind 2]
If you see the ahead and behind counts in git status and want to know which commits they refer to, you can list them with git log --oneline --left-right @{u}....





