Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I diff two branches in GitHub?

I am just wondering if there is a way to simply diff two branches in GitHub? I know GitHub has capacity to do it because when we do code-reviews it does list out all the diffs nicely. I was just wondering if there is a way to do it without any code review to compare say Branch to Branch or Commit to Commit? So that when I push something to my remote branch and I want to see how my diffs are going to look like BEFORE it create a PR then it can be very helpful.

I can always be in console and do git diff but that is really not as nice and visually clear as how it shows up in web UI of GitHub. Any ideas?

like image 571
Lost Avatar asked Oct 04 '22 08:10

Lost


2 Answers

Use the compare feature to accomplish this.

To compare different versions of your repository, append /compare to your repository's path.

like image 83
Ari M. Avatar answered Oct 09 '22 09:10

Ari M.


If you are on any branch other than the default branch (often 'master') you should see a link to compare:

Compare 1

Click it and you should get redirected to the compare-tool where you can select branches or commits to compare

Compare 2

UPDATE December 2021

GitHub seems to have hidden this option, and it is now behind the "Contribute" drop-down:

Screenshot of the "contribute" dropdown Screenshot after you click the "contribute" dropdown, showing the Compare button

like image 33
tkausl Avatar answered Oct 09 '22 11:10

tkausl