git diff $(git merge-base master branch)..branch

Merge base is the point where branch diverged from master.

Git diff supports a special syntax for this:

git diff master...branch

Since Git 2.30.0, the special syntax even gets a special switch as a shorthand:

git diff --merge-base master branch

You must not swap the sides because then you would get the other branch. You want to know what changed in branch since it diverged from master, not the other way round.

You may want to replace branch in this syntax with HEAD or even delete it completely -- all the following display the content of the current branch since it diverged from master:

git diff master...HEAD
git diff master...
git diff --merge-base master

Loosely related:

  • Finding a branch point with Git?
  • How can I see what branch another branch was forked from?

Note that .. and ... syntax does not have the same semantics as in other Git tools. It differs from the meaning specified in man gitrevisions.

Quoting man git-diff:

  • git diff [--options] <commit> <commit> [--] [<path>…]

    This is to view the changes between two arbitrary <commit>.

  • git diff [--options] <commit>..<commit> [--] [<path>…]

    This is synonymous to the previous form. If <commit> on one side is omitted, it will have the same effect as using HEAD instead.

  • git diff [--options] <commit>...<commit> [--] [<path>…]

    This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B". You can omit any one of <commit>, which has the same effect as using HEAD instead.

Just in case you are doing something exotic, it should be noted that all of the <commit> in the above description, except in the last two forms that use ".." notations, can be any <tree>.

For a more complete list of ways to spell <commit>, see "SPECIFYING REVISIONS" section in gitrevisions[7]. However, "diff" is about comparing two endpoints, not ranges, and the range notations ("<commit>..<commit>" and "<commit>...<commit>") do not mean a range as defined in the "SPECIFYING RANGES" section in gitrevisions[7].

Answer from Palec on Stack Overflow
Top answer
1 of 5
410
git diff $(git merge-base master branch)..branch

Merge base is the point where branch diverged from master.

Git diff supports a special syntax for this:

git diff master...branch

Since Git 2.30.0, the special syntax even gets a special switch as a shorthand:

git diff --merge-base master branch

You must not swap the sides because then you would get the other branch. You want to know what changed in branch since it diverged from master, not the other way round.

You may want to replace branch in this syntax with HEAD or even delete it completely -- all the following display the content of the current branch since it diverged from master:

git diff master...HEAD
git diff master...
git diff --merge-base master

Loosely related:

  • Finding a branch point with Git?
  • How can I see what branch another branch was forked from?

Note that .. and ... syntax does not have the same semantics as in other Git tools. It differs from the meaning specified in man gitrevisions.

Quoting man git-diff:

  • git diff [--options] <commit> <commit> [--] [<path>…]

    This is to view the changes between two arbitrary <commit>.

  • git diff [--options] <commit>..<commit> [--] [<path>…]

    This is synonymous to the previous form. If <commit> on one side is omitted, it will have the same effect as using HEAD instead.

  • git diff [--options] <commit>...<commit> [--] [<path>…]

    This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B". You can omit any one of <commit>, which has the same effect as using HEAD instead.

Just in case you are doing something exotic, it should be noted that all of the <commit> in the above description, except in the last two forms that use ".." notations, can be any <tree>.

For a more complete list of ways to spell <commit>, see "SPECIFYING REVISIONS" section in gitrevisions[7]. However, "diff" is about comparing two endpoints, not ranges, and the range notations ("<commit>..<commit>" and "<commit>...<commit>") do not mean a range as defined in the "SPECIFYING RANGES" section in gitrevisions[7].

2 of 5
90

Here's what worked for me:

git diff origin/master...

This shows only the changes between my currently selected local branch and the remote master branch, and ignores all changes in my local branch that came from merge commits.

🌐
KodeKloud
kodekloud.com › blog › git-diff-how-to-compare-files-between-two-branches
Git Diff: How to Compare Files Between Two Branches
November 27, 2025 - To disregard changes in whitespace during file comparisons, utilize the `-b` or `--ignore-space-change` option with the git diff command. ... This is particularly useful when whitespace modifications are not essential to your analysis. ... For a more graphical representation of the differences, you can configure a difftool and use it to visualize the changes. ... KDiff3 as our difftool to visualize the changes made to fileA.txt between the 'master' and 'feature-branch.'
Discussions

[tip] use snacks.picker to see git diff with current branch and master
You could also adapt this to show the diff between HEAD and the base of the branch, which is much more useful. More on reddit.com
🌐 r/neovim
15
40
May 28, 2025
vim - Display git-diff between master and my last commit - Unix & Linux Stack Exchange
When we work together on a shared ... current master branch (or the current HEAD). ... git fetch # download everything git merge # since I'm a trusting person ;) git logadog # my git-alias for `git log --all --decorate --oneline --graph` # manually look into how many commits were performed since my last commit git diff HEAD~3 # if ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
Understanding diff against current ?
I have two branches in source tree - master and branch-1. The current branch is master (in bold text in source tree). I right click on branch-1 and do "diff against current". Does this mean "git diff master branch-1", OR "git diff branch-1 master" ? I wanted to merge branch-1 into master. More on community.atlassian.com
🌐 community.atlassian.com
October 25, 2019
'git diff' between current workspace and master - Stack Overflow
I am a tester and have limited knowledge about Git. I have cloned a project and created a local workspace. When I want to get the latest source code, I use the git pull command. Correct me if I am... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Git
git-scm.com › docs › git-diff
Git - git-diff Documentation
Instead of comparing with the tip of "test" branch, compare with the tip of the current branch, but limit the comparison to the file "test". Compare the version before the last commit and the last commit. ... Changes between the tips of the topic and the master branches. Same as above. Changes that occurred on the master branch since when the topic branch was started off it. ... $ git diff --diff-filter=MRC (1) $ git diff --name-status (2) $ git diff arch/i386 include/asm-i386 (3)
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to compare two git branches
How to Compare Two Git Branches | phoenixNAP KB
July 3, 2025 - Git also provides the option to see how a file differs in two branches. Specify the two branches and provide the file path to get details on that specific file. ... Getting the specifics on a single file removes excess information from the output and allows you to focus on a single bug or feature that you need to address. ... The output above shows the differences between file.html on the master branch and new-branch and provides file specifics, such as file mode and index hash.
🌐
GeeksforGeeks
geeksforgeeks.org › git › how-to-see-the-differences-between-two-branches
How to See the Differences between two Branches? - GeeksforGeeks
July 23, 2025 - To see the differences between the two branches, use the following command: ... Replace <branch1> and <branch2> with the names of the branches you want to compare. For example, to see the differences between the master and feature branches:
🌐
DEV Community
dev.to › waylonwalker › today-i-learned-git-diff-master-feature-3abd
Today I learned `git diff master..feature` - DEV Community
March 13, 2020 - Things are really straightforward, and our diff will be the same between the last commit and the master branch since. Let's make another commit by adding the date. echo "hello waylon\n\n$(date)" > readme.md cat readme.md git diff ... 👆 At this point, our diff doesn't tell us the whole story between our current state and master, only between our current state and our last commit.
🌐
Unfuddle
unfuddle.com › stack › tips-tricks › git-compare-two-branches
Unfuddle Support | Git - Compare Two Branches
Compare two branches with git diff branch1..branch2. # Changes between the tips of # the feature and the master branches $ git diff feature master # OR $ git diff feature..master
Find elsewhere
🌐
Reddit
reddit.com › r/neovim › [tip] use snacks.picker to see git diff with current branch and master
r/neovim on Reddit: [tip] use snacks.picker to see git diff with current branch and master
May 28, 2025 -

Just custom finder for snacks.picker to see difference between your current branch and master branch. Sure you can choose any branch instead of master. It's useful for me, because git_status shows only current changes and i can't see them after git commit.

Snacks.picker.git_diff {
	finder = function(opts, ctx)
		local file, line
		local header, hunk = {}, {}
		local header_len = 4
		local finder = require('snacks.picker.source.proc').proc({
			opts,
			{
				cmd = 'git',
				args = {
					'-c',
					'core.quotepath=false',
					'--no-pager',
					'diff',
					'origin/master...HEAD',
					'--no-color',
					'--no-ext-diff',
				},
			},
		}, ctx)
		return function(cb)
			local function add()
				if file and line and #hunk > 0 then
					local diff = table.concat(header, '\n') .. '\n' .. table.concat(hunk, '\n')
					cb {
						text = file .. ':' .. line,
						diff = diff,
						file = file,
						pos = { line, 0 },
						preview = { text = diff, ft = 'diff', loc = false },
					}
				end
				hunk = {}
			end
			finder(function(proc_item)
				local text = proc_item.text
				if text:find('diff', 1, true) == 1 then
					add()
					file = text:match '^diff .* a/(.*) b/.*$'
					header = { text }
					header_len = 4
				elseif file and #header < header_len then
					if text:find '^deleted file' then
						header_len = 5
					end
					header[#header + 1] = text
				elseif text:find('@', 1, true) == 1 then
					add()
					-- Hunk header
					-- @example "@@ -157,20 +157,6 @@ some content"
					line = tonumber(string.match(text, '@@ %-.*,.* %+(.*),.* @@'))
					hunk = { text }
				elseif #hunk > 0 then
					hunk[#hunk + 1] = text
				else
					error('unexpected line: ' .. text)
				end
			end)
			add()
		end
	end,
}
🌐
Atlassian Community
community.atlassian.com › q&a › sourcetree › questions › understanding diff against current ?
Understanding diff against current ?
October 25, 2019 - ... The command git diff master...branch will show all changes made in branch that have not yet been merged into master, same as compare against current in Sourcetree assuming branch is your current branch.
🌐
ShellHacks
shellhacks.com › home › git – diff between branches
Git - Diff Between Branches - ShellHacks
October 24, 2018 - To show only files that are different between the two branches (without changes themselves): git diff develop..master –name-status
🌐
Git Scripts
gitscripts.com › git-diff-current-branch-with-master
Git Diff Current Branch with Master: A Simple Guide
August 23, 2025 - Git Rebase Current Branch Onto Master: A Simple Guide · The basic command to compare your current branch with the `master` branch is: ... This command is straightforward—it shows the changes in your current branch that differ from those in `master`. A more precise way to see what's different is to specify both branches: ... This command provides a clear view of the changes between the `master` branch and your current working branch.
🌐
GitHub
github.com › orgs › community › discussions › 164338
How to get "Diff with main branch" context? · community · Discussion #164338
They're asking how to replicate ... the full diff with the base branch like main. In Cursor, you can easily do: Branch (Diff with Main Branch) — to see all changes between your current branch and the main branch...
Top answer
1 of 3
10

This is the real basics of Git. I strongly recommend going through a visual Git tutorial (just google that). Also, I recommend getting the open source GUI tool Git Extensions so you can visually see your commits/branches and learn different commands easier.

Some terminology and beginner's tips:

  • You cloned a remote repository (usually called origin by default) into a local repository on your PC.
  • You do have a workspace locally, but it's a combination of several things:
    • The local Git repository itself, where all the information about the commit history is stored, this allows you to recreate the working directory for any commit.
    • The Working Directory - these are ongoing changes and differences that have not yet been committed into the repository
    • The Index - this is where changes from the working directory have been staged and are ready to be committed.
    • The Stash - this is a sort of temporary commit, where you can save the current changes from your Working directory and/or index temporarily while you go off and do something else in your repository.
  • Cloning actually creates a duplicate of the remote repository on your PC, that you can commit changes to your new local repository separately from the remote repository (then sync up with it using pull and push). Not only can you commit changes locally, updating the repository, but before you can commit changes locally, you must stage them into your index. Only items in the index get committed, and then only commits get pushed to the remote repository.
  • When you pull from the remote repository, it brings down any new commits from the current branch you have checked out (with git fetch), and then will git merge your local master branch into the remote master branch that you just pulled down.
  • Unless you have created a new branch and committed locally, you are likely in the master branch.
  • Merging may cause a merge conflict that you would have to resolve before committing the merge locally, and then finally pushing your local commits to the remote.

How to see changes ready for committing:

  • If you want to see the list of changes in your working directory (unstaged) and your index (staged and ready for a commit), type git status.
  • If you also want see the actual changes in each file that is changed, then you can type git diff HEAD.

Although it's really easy in Git Extensions to see the current changes - just hit the "Commit" button, and a window pops up with the working directory on top left, index on bottom left, and if you click on any file in them, you'll see all the changes for that file on the right side.

This is Not the Diff You're Looking For

(Sorry - couldn't resist the Star Wars quote)

Okay, I finally understand your core question - you are not making changes to the local repository, you just want to see the changes between the repository before the pull and after the pull - to see what changed since the last time you pulled.

This can be done by getting the hash of the last commit on master before the pull, and then using:

git diff <hash of prior commit> HEAD

HEAD refers to whichever commit is currently checked out, either the current commit of the branch you checked out, or a particular commit if you checked one out directly (this is a state called a "detached HEAD"). HEAD will point to master which will should point to the latest commit in the repository after a successful pull.

Instead of using HEAD, you could put the actual hash of the latest commit. Note that if you know how many commits were pulled down, you don't even need to know the commit hashes. For example, if the prior commit was two commits back, you can use:

git diff HEAD~2 HEAD

The HEAD~2 just looks two commits back in the log from HEAD, and uses that hash.


To do this with a GUI, in Git Extensions, you can just right-click on the prior commit and select "Compare → Compare to current branch" in order to pull up the diff window with the changes between that commit and the current location of your current branch.

The currently checked out branch/commit is shown in bold in Git Extensions, and should always be at the top of the list and have a >master tag next to it for your situation.

2 of 3
1

In general, you are always on a branch in Git (an exception might the detached head state). Unless you recall creating a branch, my guess is that you are on the master branch. To see changes you have made relative to where you began, you can use the following from the command line:

git diff HEAD

If you are using an IDE such as IntelliJ or Eclipse, with a Git plugin, then you can visually see many more types of diffs of the files in your workspace.

🌐
CodeGenes
codegenes.net › blog › git-diff-between-current-branch-and-master-but-not-including-unmerged-master-commits
How to Git Diff Current Branch and Master Excluding Unmerged Master Commits — codegenes.net
HEAD: Your current branch’s latest commit. Output: A commit hash (e.g., a1b2c3d), the common ancestor A. ... This compares the merge base (A) to your branch’s latest commit (E), showing only your changes (D and E). Git’s three-dot notation (master...HEAD) is a shortcut for diffing from the merge base to your branch’s HEAD.
🌐
Educative
educative.io › answers › how-to-compare-files-from-two-different-branches-in-git
How to compare files from two different branches in Git
The code above will show the difference between the test.js files in the my_master and the master branch. The -- command denotes the end of command-line flags. This is optional unless Git gets confused if the argument refers to a commit or a file. If we want to compare the test.js file from the current branch to the other branch then the current branch name can be skipped by adding ...
🌐
Linux find Examples
queirozf.com › entries › git-diff-reference-and-examples
Git Diff: Reference and Examples
April 28, 2025 - $ git diff origin/master diff --git a/file3.txt b/file3.txt new file mode 100644 index 0000000..a309e46 --- /dev/null +++ b/file3.txt @@ -0,0 +1 @@ +this is file3 · Only files that have been staged (git added) will show up. Use git diff <remote_name>/<branch_name> -- . Example: diff between ...
🌐
GitHub
github.com › actions › checkout › issues › 160
Diff between PR and master · Issue #160 · actions/checkout
February 20, 2020 - Running git diff master HEAD on a local copy of the repository works fine: git clone <repo> git checkout pr-branch git diff master HEAD
Author   actions