简体   繁体   中英

After a github fork, how can I compare my branch to a branch in the upstream repo?

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM