How to compare a local Git branch with its remote branch
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 the remote repository.
How to compare a local Git branch with its remote branch
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.)
How to compare a local Git branch with its remote 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