Compare Code From Two Git Branches — Free Online Method
Table of Contents
Git has built-in diff for comparing branches: git diff branch1..branch2 gives you the unified diff between two branches. But unified diff format is dense, and comparing a specific function across branches is difficult when the diff includes dozens of other changed files.
For targeted cross-branch comparison, extracting the function from each branch and diffing it in a browser tool like Raven Code Diff gives you a cleaner, more readable result. Here's how.
Git's Built-In Diff vs Targeted Function Comparison
Git diff for branch comparison:
git diff main..feature-branch— shows all changes between two branchesgit diff main..feature-branch -- path/to/file.py— scoped to one filegit show main:path/to/file.py— shows the file as it exists in the main branch
These commands work well when you want the full picture. But for comparing a specific function across branches — especially in large files where git diff shows too much context — a targeted extraction and paste is faster to reason about.
Sell Custom Apparel — We Handle Printing & Free ShippingHow to Extract and Compare a Function From Two Branches
Step-by-step:
- View the function in branch A:
git show main:src/utils.py | grep -A 30 "def process_data"— this shows 30 lines of the function starting from its definition in main - Copy the output to a temp note
- Repeat for branch B:
git show feature-branch:src/utils.py | grep -A 30 "def process_data" - Paste both versions into Raven Code Diff — original on left, branch B version on right
- Select your language and click Compare
You get a clean, focused diff of just that function, with syntax highlighting, line numbers, and color coding — without the noise of the full branch diff.
When to Use This Approach vs Standard git diff
Use git diff branch1..branch2 when: You want the full picture — all files changed, all functions, in one view. This is the right tool for a comprehensive branch comparison.
Use the extract-and-paste method when:
- You're focused on one specific function and don't want the noise of the full diff
- The file is large and git diff context is hard to navigate
- You want syntax highlighting beyond what your terminal provides
- You're sharing the comparison with someone who doesn't have git access
- You're comparing on a machine without git installed (e.g., a production server you've SSH'd into)
Both approaches belong in a developer's workflow. Terminal git diff for comprehensive analysis; browser diff for targeted, readable comparisons.
Try It Free — No Signup Required
Runs 100% in your browser. Your code never leaves your device.
Open Free Code Diff ViewerFrequently Asked Questions
How do I compare two branches in git?
Use "git diff branch1..branch2" to see all changes between two branches. Add "-- path/to/file" to scope it to a specific file. Use "git show branch:path/to/file" to see the full file content as it exists in a specific branch.
How do I compare a specific function between two git branches?
Run "git show branch1:file.py" and "git show branch2:file.py" to get both versions, extract the function from each output, then paste both into Raven Code Diff. You get a focused diff of just that function with syntax highlighting.

