Git Diff Between Main and Feature Branch

Quick Linux Tip #77:

Question: How do I see all differences between production and my feature branch?

Try: git log --oneline --left-right --graph main...feature/new-api

Info: The three-dot ... notation compares the two branches from their common ancestor. --left-right marks commits unique to the left branch with < and commits unique to the right branch with >, making branch divergence easy to identify.

Examples:

  • $ git log main..feature --oneline  # Show commits reachable from feature but not main
  • $ git diff main...feature -- '*.js'  # Show file changes introduced by the feature branch
  • $ git range-diff main..feature@{yesterday} main..feature  # Compare changes between two versions of a branch

Note: Two dots (..) and three dots (...) have different meanings in Git. main..feature lists commits reachable from feature but not main, while main...feature uses the common ancestor when calculating the comparison. For a typical pull-request review, git diff main...feature shows the changes introduced by the feature branch since it diverged from main.




LinuxTeck.com
linuxteck@ubuntu:~$ git log --oneline --left-right --graph main...feature/new-api
* > 8a3f2c1 feat: add rate limiting to /api/v2
* > 7b2e1d0 fix: handle empty requests body
* > 6a1d0c9 test: add integration tests for API
* > 5f0c9b8 refactor: extract auth middleware
| * < 4e9b8a7 hotfix: patch CVE-2026-1234
| * < 3d8a7b6 fix: typo in error message

linuxteck@ubuntu:~$ git diff main...feature/new-api --stat
src/api/v2/rate_limiter.js | 234 ++++++++++++++++++++
src/middleware/auth.js      | 45 +++--
tests/api_integration.js    | 156 ++++++++++++
3 files changed, 421 insertions(+), 14 deletions(-)
linuxteck@ubuntu:~$

PREVIOUS ARTICLE Quick Linux Tip #76: Generate a Self-Signed SSL Certificate with OpenSSL NEXT ARTICLE Quick Linux Tip #78: How to Monitor Network Interface Traffic in Linux with sar
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.