How to compare a local git branch with its remote branch?

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 remote repository.


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) then choose branch name from list (just remove remotes/ from remote branch name.

Example: git diff main origin/main (where "main" is local main branch and "origin/main" is a remote namely origin and main branch.)


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

Tags:

Git

Diff