4

I'm comparing dev branch in my fork with the dev branch in the upstream. It shows diff of 30 commits, but 0 files changes. All the commits appear in the diff are old commits which already merged to the upstream (mainly type of "Merge branch dev.."). This makes an issue where each PR shows those many old commits. Tried rebase and still showing the same diff.

Why this happens? Can you please assist how to resolve? We're using Github for Enterprise so can't attach a url that show the diffs.

Seffy
  • 1,045
  • 1
  • 13
  • 27

1 Answers1

2

Why this happens?

Possibly because you might have done PR (Pull Requests) from yourFork(origin)/dev and upstream/dev, which is not a good practice.
You would normally do a PR from a dedicated branch (myfix) to upstream/dev. And then simply reset your own dev to upstream/dev, in order to have in your fork an exact image of upstream/dev, and:

  • make new fix/feature branches for future PRs,
  • rebase existing fix/feature branches on top of dev in order to facilitate future PRs.

If everything is committed or stashed locally, I would:

  • create a dedicate branch (myfix or myfeature) right where my local dev is (assuming I was developing the next PR directly on dev)
  • reset dev to upstream dev

That is:

git switch dev
git branch myfix
git fetch upstream
git reset --hard upstream/dev
git push --force
git switch myfix
# resume working
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the fast response! I supposed we should "git push" after the reset to make the fork updated? – Seffy Oct 15 '20 at 11:13
  • @Seffy yes, a force push. I have edited the answer accordingly. – VonC Oct 15 '20 at 11:16
  • from now on I should update my fork using "git pull upstream dev" and "git push", will that make my dev branch aligned as expected? – Seffy Oct 15 '20 at 11:28
  • 1
    @Seffy Yes. I would actually [change the upstream branch](https://stackoverflow.com/a/4879224/6309) for `dev`: `git branch dev -u upstream/dev` and `git remote set-url --push upstream url/of/fork`, that way a simple `git pull` is enough: it will pull from the right remote for `dev` and still push to your fork. – VonC Oct 15 '20 at 11:57