Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare a local Git branch with its remote branch

Tags:

git

diff

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

like image 273
mrblah Avatar asked Nov 25 '09 23:11

mrblah


People also ask

How do I know if my remote and local branch are the same?

You can use git rev-list . Simply call git rev-list feature_branch... origin/feature_branch (symmetric difference). If there is no output, both commits are the same.

How do you tell which remote branch a local branch is tracking?

1 Answer. There is a command that gives you about all tracking branches. And to know about the pull and push configuration per branch you can use the command git remote show origin. and you can use -sb option for seeing the upstream.


2 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.

like image 89
Jakub Narębski Avatar answered Sep 17 '22 13:09

Jakub Narębski


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

like image 25
meder omuraliev Avatar answered Sep 17 '22 13:09

meder omuraliev