gitdiff

How to compare a local Git branch with its remote branch


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


Solution

  • 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.)