I was trying to compare changes I made to a forked repo.
To make this real, here is the example:
- I forked https://github.com/springframeworkguru/sfg-di as https://github.com/steranka/udemy-sfg-di.
- I got a local copy of the (forked) repo
git clone [email protected]:steranka/udemy-sfg-di.git
- I changed to the branch I wanted to work on
git checkout property-source
. - Made changes and committed the changes (to my local repo).
- 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: [email protected]:steranka/udemy-sfg-di.git
upstream: [email protected]: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:
https://stackoverflow.com/a/66613981/3281336. Basically do the compares via local repo.
How to compare a local Git branch with its remote branch - How to compare local vs remote branch. Later, I learned this is basically what a forked repo is... Just another remote.
General info about forks (from GitHub.com) https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-comparing-branches-in-pull-requests - The GitHub.com docs indicate that this is doable if you create a pull request. This is not what I want to do.
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?
CodePudding user response:
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.
CodePudding user response:
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:
- Setup the pointers to the upstream (the repo you forked)
- Get the upstream source and put it into your local repo
- Compare the upstream source's (local copy) to your code.
The code commands to do this are:
git remote add upstream [email protected]: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.