4

Suppose there is a GitHub repository named upstream/project. Let's say that I have a fork of it named fork/project. I commit some changes to fork/project and initiate a pull request to upstream/project. Once the pull request is accepted, why does fork/project become 1 commit behind upstream/project?

The code in the upstream repo now matches the code in my fork. Why must I pull again from the upstream repo just to end up in the same state? Couldn't the upstream repository be brought exactly in sync with the fork, rather than "overshooting" it?

I'm hoping for an answer that explains either the advantage that this system provides or the limitation that demands this workflow, whichever the case may be. Thanks!

Tashus
  • 207
  • 2
  • 9

2 Answers2

1

As hinted at by SLaks in comment, the difference is the merge commit made on upstream/project.

When your pull request is accepted, branches are merged and a commit is made on upstream/project, but fork/project is not aware of this before you pull again from upstream.

When you pull, fork/project starts by fetching that new commit, then just fast-forwards without need for a merge. Only then are both trees identical.

About the strategy :

The very broad picture is that merge strategy (discussed here) is more noisy and a bit clunkier in terms of tree structure because of all the merge commits. In the other hand, rebase strategy is leanier but also trickier, with nasty situations to get out of if people use it carelessly.

To go further on the "strategy" part, there are a lot of comparisons with excellent answers already, just search along the lines of "merge/rebase debate".

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
1

I'm hoping for an answer that explains either the advantage that this system provides or the limitation that demands this workflow, whichever the case may be.

If what you're really asking is this:

why did upstream not merge with fast-forward?

Merge-commit/no-fast-forward strategy is very useful for merging PRs, because it allows reverting changes in just one step (because there's only one commit, regarless of how many were in the original branch). This alone is enough to make it the go-to strategy.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367