0

I was trying to compare changes I made to a forked repo.

To make this real, here is the example:

  1. I forked https://github.com/springframeworkguru/sfg-di as https://github.com/steranka/udemy-sfg-di.
  2. I got a local copy of the (forked) repo git clone git@github.com:steranka/udemy-sfg-di.git
  3. I changed to the branch I wanted to work on git checkout property-source.
  4. Made changes and committed the changes (to my local repo).
  5. Push my changes to my fork so the changes can be compared to the original repo. git push

Now I want to compare my changes to the equivalent branch on the original repo.

The origin and upstream are set to:
origin: git@github.com:steranka/udemy-sfg-di.git
upstream: git@github.com:springframeworkguru/sfg-di.git

Searching for solution

My searches indicated that there was not a built in way to do this using the git CLI, nor the github website.

What I did find was:

My question

How do you do this? I ran across gh-cli which might do it.
Can this be done via the github.com web interface? If so, how?

torek
  • 448,244
  • 59
  • 642
  • 775
PatS
  • 8,833
  • 12
  • 57
  • 100

2 Answers2

2

Append /compare to the URL of your repo. Example (try it):

https://github.com/mattneub/amperfy/compare

That's a public fork of a public upstream. You can select two branches, possibly at the two different repos, to see the diff.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • This is exactly what I was looking for. I'm not sure if this will work for others but the URL that I ended up with to compare the two branches was: https://github.com/springframeworkguru/sfg-di/compare/property-source...steranka:udemy-sfg-di:property-source – PatS Dec 29 '22 at 02:45
0

I've selected the answer from Matt because that is the answer I was looking for. But another possible solution is based on @torek's answer.

The solution is to pull the upstream repo's branch that you want to compare locally and then do normal git diff commands. The result is that the compares are done via my local repo.

The steps to do this are:

  1. Setup the pointers to the upstream (the repo you forked)
  2. Get the upstream source and put it into your local repo
  3. Compare the upstream source's (local copy) to your code.

The code commands to do this are:

git remote add upstream git@github.com:springframeworkguru/sfg-di.git
git fetch upstream property-source
git diff upstream/property-source..

This turned out to be simpler than I expected.

One benefit of this approach over the GITHUB web ui is I could compare my code changes without pushing my code to the github.

PatS
  • 8,833
  • 12
  • 57
  • 100