How can I see the diff
between a local branch and a remote branch?

- 30,738
- 21
- 105
- 131

- 99,669
- 140
- 310
- 420
-
13This questions was asked again later. It has a nice answer: http://stackoverflow.com/questions/11935633/git-diff-between-remote-and-local-repo – rustybeanstalk Oct 17 '13 at 05:27
-
5example: git diff master origin/master (where master is local master branch and origin/master is remote master branch). – Dung May 01 '17 at 17:56
-
@klyngbaek, this [answer](https://stackoverflow.com/a/33289679/8554766) in particular ;-) – Sep 11 '18 at 08:52
-
I was originally trying `git diff HEAD origin/HEAD` which seems to point to a different remote branch than the one I intended. Using the full branch name works as expected. – Deanna Dec 03 '18 at 15:44
24 Answers
git diff <local branch> <remote>/<remote branch>
For example, git diff main origin/main
, or git diff featureA origin/next
Of course to have said remote-tracking branch you need to git fetch
first; and you need it to have up-to-date information about branches in the remote repository.

- 30,738
- 21
- 105
- 131

- 309,089
- 65
- 217
- 230
-
106
-
58I usually do `git diff
/ – Michał Tatarynowicz Aug 12 '13 at 12:51` to see what my push will do to remote repo. -
112The even shorter `git diff origin` is sufficient if you just compare with your upstream branch. – Ludder Apr 10 '14 at 12:40
-
24please add `git fetch` at the beginning,it cause trouble to newbie like me – Saif Mar 25 '15 at 15:59
-
The `git branch -a` below really completes the picture. It shows you all of your remote branches, for easy diff'ing. – Mike S Sep 03 '15 at 21:04
-
3Hey, shouldn't it be `git diff
/ – Martín Coll Feb 06 '16 at 00:48`? Otherwise, I get the adds and deletes switched on my computer (git version 2.7.0.windows.2) -
6@Ludder, I think you meant `git diff @{upstream}` instead? `git diff origin` always shows me `origin/master` no matter what branch I have checked out. – carej Mar 15 '16 at 23:00
-
1`origin` expands to the default branch, not the tracked branch. – Niels Keurentjes May 18 '16 at 18:58
-
@carej and @NielsKeurentjes: `origin` expands to what `origin/HEAD` points to, i.e. default branch; you can change where `origin` as a branch shortcut points to with the `git remote` command (in modern Git). – Jakub Narębski May 19 '16 at 10:22
-
1`git diff master origin/master` will only show differences if they have been committed, `git diff origin` or `git diff @{upstream}` will show differences even if they have not been committed. – Akavall Feb 12 '17 at 03:49
-
2Order matters. For ex., `git diff master origin/master` will show, what difference is present in remote file (compared to local _commited_ file), while `git diff origin/master master` will show, what difference is present in file from local repository (ie, commited) compared to remote file. And `git diff origin` is the same as `git diff origin/master master` **+** uncommited changes. – Boolean_Type Apr 23 '17 at 16:57
-
if you have some branch in two different remotes, you can compare them using `git diff
/ – y2k-shubham Aug 21 '22 at 13:52/ `
To update remote-tracking branches, you need to type git fetch
first and then:
git diff <mainbranch_path> <remotebranch_path>
You can git branch -a
to list all branches (local and remote) and then choose the branch name from the list (just remove remotes/
from the remote branch name.
Example: git diff main origin/main
(where "main" is the local main branch and "origin/main" is a remote, namely the origin and main branch.)

- 30,738
- 21
- 105
- 131

- 183,342
- 71
- 393
- 434
-
51
-
2That just shows a sneak into the changes in bash, is there any way to open all changes in an IDE like VS code? – Harsh Phoujdar May 05 '20 at 08:37
-
@Harsh Phoujdar Add the below code in your .git/.gitconfig file `[diff] tool = vscode [difftool] prompt = false [difftool "vscode"] cmd = \"C:\\Program Files (x86)\\Microsoft VS Code\\Code.exe\" \"$LOCAL\" \"$REMOTE\" --diff --wait trustExitCode = false` Make sure your path to code.exe file is correct. – Aman May 05 '20 at 19:59
-
On VS Code there is the [Git Lens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens) extension that is very helpfull on this and many other ways. On new GitLens tab > Repositories: There is a list of all files changed by commits ahead with a side-by-side preview on click. – Traxidus Wolf Jun 28 '20 at 09:59
If you're on a given branch, and you want to compare your working copy with the upstream branch you're tracking, use:
git diff @{upstream}
If you want to compare your current HEAD with the upstream branch (thanks @Arijoon):
git diff @ @{upstream}
If your upstream isn't set, you can use @{push}
to get a diff against the branch you are set to push to (also from @Arijoon's comment):
git diff @{push}
Courtesy of this answer, the git documentation for specifying revisions has:
<branchname>@{upstream}
, e.g.master@{upstream}
,@{u}
The suffix@{upstream}
to a branchname (short form<branchname>@{u}
) refers to the branch that the branch specified bybranchname
is set to build on top of (configured withbranch.<name>.remote
andbranch.<name>.merge
). A missingbranchname
defaults to the current one.

- 4,939
- 29
- 31

- 78,473
- 57
- 200
- 338
-
19Very good answer just missing a little part. Change the line to `git diff @ @{upstream}`. The extra `@` is `HEAD`, which is where you are now, so you are comparing `HEAD` with the upstream your branch is tracking. You can use `@{push}` instead of upstream to get diff between the branch you are set to push to – Arijoon Apr 01 '17 at 14:21
-
9best answer, doesn't require fetching the remote. needs more upvotes! – jcomeau_ictx Jun 16 '17 at 17:24
-
4In fish shell I got result: `fatal: ambiguous argument '@upstream': unknown revision or path not in the working tree`. Had to use `git diff @\{upstream\}` instead. – Landon Kuhn Sep 20 '17 at 17:13
-
You need to `git fetch` first, else this does nothing, shows no output; tested by deleting a file in the repo origin and ran this command locally. ..works only after fetch. – Nov 21 '18 at 21:44
-
Also, as the answer as given includes any local changes. sometimes this is desired, other times, not. – Deanna Dec 03 '18 at 15:46
-
`fatal: ambiguous argument '@{origin}': unknown revision or path not in the working tree.`. Based on comment above about problem with fish *(I'm on zsh though)*, I made it to somewhat work as `git diff @\\{origin\\}`. However the diff was empty, even though I changed one commit and I know it shouldn't be. So no, this answer doesn't work at all. – Hi-Angel Aug 12 '19 at 07:28
-
`fish`/`zsh`, comment the argument with single quotes so that no shell replacement happens. i.e. `git diff @ '@{u}'`. Read the shell manual to understand the replacment rules for your shell. Quoting with single quotes will work in _all_ shells though. – Matt Clarkson Jan 22 '20 at 09:35
-
If you want to view the diff for the current HEAD from the perspective of "what did I add/remove/change that isn't yet on the remote" (i.e. a new file shows up as additions not subtractions), just switch the order: `git diff @{upstream} @` – hlongmore Apr 25 '22 at 22:55
-
The other answers are good, but i find this one easiest to work with using git hooks since it doesn't require a bunch of extra steps for branch names. `@{push}` specifically is the piece I'm using. – Arthur Weborg Jan 11 '23 at 22:00
-
`git diff @{upstream}` solves my need. I just added an alias to my .gitconfig `diffu = diff @{upstream}` – Doug Harris Feb 16 '23 at 18:03
First type
git branch -a
to get the list of available branches. On the output you may see something like
* master
remotes/main/master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/mt
remotes/upstream/master
remotes/upstream/mt
Then show the diff
git diff --stat --color remotes/main/master..origin/master
git diff remotes/main/master..origin/master

- 2,504
- 1
- 14
- 12
-
2
-
10I would definitely have chosen this as the answer. Following your directions, I was able to view the differences between a local branch and a remote branch. Thanks! – Tass May 28 '13 at 17:10
-
1I usually do `git log origin/my_branch..` which will take `HEAD` as local ref, which is mostly what you mean. – Rudie Oct 22 '13 at 21:15
-
5+1 for best answer in my humble opinion. Would be worthy of +2 if you mentioned "fetch" to synchronize the "remote" image of the cloned source. The stat/color overview step is particularly helpful. – bvj Sep 04 '14 at 05:39
-
As diff is about two endpoints, and not about revision range like log, therefore `git diff A..B` is `git diff A B`, and `git diff A...B` is `git diff $(git merge-base A B) B` - the syntax is to make it possible to copy'n'paste `git fetch` output both to `git log` and `git diff`. – Jakub Narębski Sep 04 '15 at 15:14
-
Why dots at all between the branches being diff'd? Is that any different than just using a space? Edit: documentation is at https://git-scm.com/docs/git-diff – Woodchuck Nov 08 '17 at 16:42
-
5Thanks for the one answer that finally worked out of the seven or eight "answers" that resulted in little more than `fatal: bad revision` or `fatal: ambiguous argument`. All I wanted was to see the diff on the same file from another branch, was that too much to ask? Yes, yes it was. :-) `git diff remotes/origin/
-- – Steve Bonds Apr 25 '18 at 21:22` works great on git 1.8.3.1 -
This is the better answer. The previous answers are too abstract and do not include the exploratory first step. – Peter Mortensen Jun 13 '21 at 11:29
-
Can you respond to [Eliran Malka's comment](https://stackoverflow.com/questions/1800783/how-to-compare-a-local-git-branch-with-its-remote-branch#comment22638957_10130388)? – Peter Mortensen Jun 13 '21 at 11:30
-
Do the examples really use a local branch (as in the question)? Can you elaborate [in your answer](https://stackoverflow.com/posts/10130388/edit)? – Peter Mortensen Jun 13 '21 at 11:37
-
Why do the examples include "origin/"? Shouldn't it be left out? Can you elaborate in your answer? – Peter Mortensen Jun 13 '21 at 11:46
-
Can someone rewrite this for main instead of master? I'm not having success just changing the word master to main – Marjorie Roswell Jun 19 '21 at 15:35
I understand much better the output of:
git diff <remote-tracking branch> <local branch>
That shows me what is going to be dropped and what is going to be added if I push the local branch. Of course it is the same, just the inverse, but for me it is more readable, and I'm more comfortable looking at what is going to happen.

- 30,738
- 21
- 105
- 131

- 497
- 4
- 2
The easy way:
git fetch
git log -p HEAD..FETCH_HEAD
This will first fetch the changes from your default remote (origin). This will be created automatically when you clone a repository. You can also be explicit: git fetch origin master
.
Then git log
is used to compare your current branch with the one just fetched. (The -p
(generate patch) option is what shows the differences.)

- 30,738
- 21
- 105
- 131

- 9,103
- 6
- 53
- 57
TLDR: git diff <local branch> <remote branch>
When using Git in the shell, I like to first orient myself by looking around.
Here's a command to show all branches
$ git branch -a # (or git branch --all)
* my-branch
master
remotes/origin/some-branch
remotes/origin/HEAD -> origin/master
remotes/origin/my-branch
remotes/origin/some-other-branch
remotes/origin/master
Here I have two local branches (my-branch
and master
) and four remote branches (some-branch
, some-other-branch
, master
, and my-branch
).
Also, the asterisk next to my-branch
signals the fact that I'm currently in that branch (you would also know that by using the command git status
that would output: On branch my-branch.
).
Note: the remote branches in the Git Bash shell are shown in red while the local ones are shown in green.
If you just want to show remote branches:
$ git branch -r # (or git branch --remotes)
origin/some-branch
origin/HEAD -> origin/master
origin/my-branch
origin/some-other-branch
origin/master
To show just local branches you might be tempted to use git branch -l
, but that's a completely different command. To show local branches use git branch
with no options
$ git branch
* my-branch
master
To complete a review of the basic branch options, there's the --list
that, contrary to what you might expect, is there to allow filtering. Use it with a pattern like this:
$ git branch --list 'my*'
* my-branch
You can also combine --list
with the options -a
and -r
, but make sure to adapt your pattern accordingly (remember: remote branches start with "remotes").
Example:
# This will show all branches (local & remote) that start with my
$ git branch --list 'my*' -a
* my-branch
# Better: the pattern includes the remote
$ git branch --list '*my*' -a
* my-branch
remotes/origin/my-branch
Documentation: git-branch
Now you can compare any two branches from all the available ones (you can also compare two locals or two remotes).
Here I'm comparing the local with the remote my-branch
. They're synchronized, so I don't get any output:
$ git diff my-branch remotes/origin/my-branch
Note: you have to give the full names of the branches with no quotation marks.
I can also compare the local my-branch
to the remote master
. Here I get some output, because the remote my-branch
hasn't been merged into the master branch.
$ git diff my-branch remotes/origin/master
diff --git a/src/controllers/call.controller.js b/src/controllers/call.controller.js
index fd79b98..df3d798 100644
--- a/src/controllers/call.controller.js
+++ b/src/controllers/call.controller.js
@@ -261,7 +261,7 @@ function callController() {
/*
* Function: doCall
[ . . . ]

- 30,738
- 21
- 105
- 131

- 27,088
- 20
- 102
- 114
This is how I do it.
# To update your local.
git fetch --all
This will fetch everything from the remote, so when you check difference, it will compare the difference with the remote branch.
# To list all branches
git branch -a
The above command will display all the branches.
# To go to the branch you want to check difference
git checkout <branch_name>
# To check on which branch you are in, use
git branch
(or)
git status
Now, you can check the differences as follows.
git diff origin/<branch_name>
This will compare your local branch with the remote branch.

- 30,738
- 21
- 105
- 131

- 4,935
- 2
- 32
- 34
-
2git fetch --all will fetch everything from ALL remotes. git fetch should be sufficient if you use the default origin remote. – Christophe Keller Jun 19 '17 at 06:58
-
Amazing that after 8 years, we get a complete answer that properly explains the steps. We can do a --help to get the commands. SO is about understanding them. – gdbj Aug 02 '17 at 14:27
Here is a shorthand answer if you are comparing your current branch and to something you want to git pull
.
git fetch
git diff FETCH_HEAD
The first command will figure out which remote branch corresponds to your current branch. An artefact of that calculation in the FETCH_HEAD
reference. Then the second command uses that reference to compare versus what your current branch has.

- 30,738
- 21
- 105
- 131

- 37,208
- 23
- 149
- 195
-
Great, `FETCH_HEAD` is exactly what I was missing. Just a small detail: in case you want to take the last local commit as baseline and see what has changed in origin, run `git diff HEAD FETCH_HEAD` – bgusach Jun 30 '22 at 06:47
Let your working branch be development and you want to differentiate between the local development branch and the remote development branch. In that case, the syntax should be like:
git diff remotes/origin/development..development
Or
git fetch origin
git diff origin/development

- 30,738
- 21
- 105
- 131

- 1,954
- 16
- 17
If you want to see the difference as just the names of the files changed then use:
git diff --name-status <remote-branch> <local-branch>
Else this would show all differences between the two branches:
git diff <remote-branch> <local-branch>

- 30,738
- 21
- 105
- 131

- 189
- 1
- 11
-
Does this require a Git fetch or not? Why or why not? Please respond by [editing your answer](https://stackoverflow.com/posts/40375132/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the answer should appear as if it was written today). – Peter Mortensen Jun 13 '21 at 11:53
In my case I have a second remote called heroku
that is not the origin
and because it wasn't in sync, I got this error when trying to run the git diff master heroku/master
:
fatal: ambiguous argument 'heroku/master': unknown revision or path not in the working tree.
Or this when trying the other approach git diff master..heroku/master
:
fatal: bad revision 'master..heroku/master'
The solution was explicitly mentioning the remote name in git fetch
before running git diff
, in my case:
$ git fetch heroku
$ git diff master heroku/master

- 30,738
- 21
- 105
- 131

- 2,293
- 2
- 24
- 31
git difftool <commit> .
This will compare the commit you want with your local files. Don't forget the dot in the end (for local).
For example, to compare your local files with some commit:
git difftool 1db1ef2490733c1877ad0fb5e8536d2935566341 .
(and you don't need git fetch, unless comparing to new commits is needed)

- 746
- 1
- 9
- 25
-
I think tis is interesting because is a comparison I can make before commit and push. Unfortunately in windows vimdiff for showing is ugly; is there any way to use anything better, like notepad++? – Stefano Scarpanti Aug 01 '17 at 10:22
Try:
git diff origin HEAD
Assuming you want to diff you current local branch's HEAD
against the origin.
And assuming you are on the local branch. :)

- 30,738
- 21
- 105
- 131

- 75
- 2
-
I tried this 5 minutes ago and it's still scrolling through, having decided that every single file in my project is different – Healyhatman Jun 23 '21 at 06:17
-
I wonder about if there is any change in my master branch...
Firstly, you need to change your branch (If you are already under this branch, you do not need to do this!):
git checkout master
You can see which file has been modified under your master branch by this command:
git status
List the branches
git branch -a
- master
remotes/origin/master
- master
Find the differences
git diff origin/master

- 30,738
- 21
- 105
- 131

- 429
- 4
- 5
First thing you need to do is run:
git fetch
on your local branch
if you see changes in console result like :
'diff --git a/versions.txt b/versions.txt
index 82d6379..794e6c7 100644
--- a/versions.txt
+++ b/versions.txt
@@ -9,3 +9,4 @@ version8
version 9 let it fetch yes
let see changes ok ?
another line
+second line^M'
, that's mean that there are changes in that remote repo that aren't in your local one, you can check remote repositorie is ahead of local repositorie using:
git log origin/master
git log remote repo/local repo
now run :
git diff master origin/master
git diff localRepo remoteRepo/localRepo so you can see the difference
note that running : git log origin/master as first step will not show if there are changes or not, you must fetch first
then you can pull those changes into your local repositorie using :
git pull origin master
git pull remoteRepo localRepo

- 160
- 9
Example
git diff 'master' 'testlocalBranch'
If you are using an editor like WebStorm, you can right click on a file, select compare with branch, and type/select your branch.

- 30,738
- 21
- 105
- 131

- 6,386
- 27
- 127
- 202
-
2What does this add over the 7.5 year old accepted answer with 170+ upvotes? – Mark Rotteveel Apr 15 '17 at 08:42
-
This is For mrblah the user or for similar users who added comment for the accepted answer. Syntax is different from an example and example helps more from beginner's point of view. – Kurkula Apr 15 '17 at 14:55
-
2
I kept seeing this error
git diff main origin/master
fatal: ambiguous argument 'main': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Solution: I had to git push
first (since both the remote and local need to be up to date), and then this worked:
git diff master origin/master

- 41,291
- 27
- 223
- 311
-
1But then both local and remote are up to date and there's no delta? Doesn't that defeat the point of the diff? – Owl Nov 10 '22 at 16:56
-
@Owl I think you're right. I have no idea what I was doing at the time, but looking at the code I ran that produced the error, I suspect I may have tried `main` on an older repo that didn't have a branch called main (just `master`). But I'm just guessing. In all honesty I would ignore my answer here. I will consider deleting it as I can't see it actually helping. – stevec Nov 10 '22 at 17:03
-
i don't blame you at all though, it's obvious what you meant in your first command, not sure why git couldn't figure it out. – Owl Nov 10 '22 at 17:20
This is quite simple. You can use: git diff remote/my_topic_branch my_topic_branch
Where my_topic_branch
is your topic branch.

- 3,489
- 2
- 22
- 29
FWIW you can use the --compact-summary
option.
man git diff
Output a condensed summary of extended header information such as file creations or deletions ("new" or "gone", optionally "+l" if it’s a symlink) and mode changes ("+x" or "-x" for adding or removing executable bit respectively) in diffstat. The information is put between the filename part and the graph part. Implies --stat.
e.g.
git diff $(current_branch) origin/$(current_branch)

- 525
- 7
- 19
-
In case anyone else sees this answer, I needed to swap the positions of current branch and origin/current_branch. Using the command as-is, if you had added files to your current local branch, those files wouldn't be reflected in the diff. `git diff origin/main $(git branch --show-current) ` – SW_user2953243 Aug 02 '22 at 22:57
A convenient one-liner for diffing the current branch with its state in the remote (i.e. how to answer the question "what's going to change when I push?") as follows:
git diff origin/$(git rev-parse --abbrev-ref HEAD)

- 1
- 1
Setup
git config alias.udiff 'diff @{u}'
Diffing HEAD with HEAD@{upstream}
git fetch # Do this if you want to compare with the network state of upstream; if the current local state is enough, you can skip this
git udiff
Diffing with an Arbitrary Remote Branch
This answers the question in your heading ("its remote"); if you want to diff against "a remote" (that isn't configured as the upstream for the branch), you need to target it directly. You can see all remote branches with the following:
git branch -r
You can see all configured remotes with the following:
git remote show
You can see the branch/tracking configuration for a single remote (e.g. origin) as follows:
git remote show origin
Once you determine the appropriate origin branch, just do a normal diff :)
git diff [MY_LOCAL] MY_REMOTE_BRANCH

- 2,423
- 27
- 30
Let's say you have already set up your origin
as the remote repository. Then,
git diff <local branch> <origin>/<remote branch name>

- 598
- 5
- 9
In Visual Studio 2019, just do fetch. Do not pull code.
This is what I did. I added the below in the .gitconfig file so that I can use Beyond Compare
File location: C:\Users\[username]\.gitconfig
Added below
[diff]
tool = bc
[difftool "bc"]
path = c:/Program Files/Beyond Compare 4/bcomp.exe
Open a command prompt and go to the working directory. I gave the below to compare the local dev branch to the remote dev branch:
git difftool dev origin/dev --dir-diff
This will open Beyond Compare and open directories which have files that differ. If there aren't any changes, Beyond Compare will not launch.

- 30,738
- 21
- 105
- 131

- 3,361
- 3
- 43
- 61