Search code examples
gitgithubgit-mergepull-request

Implications of Git Pull Request from an identical branch of my own repo


I'm a beginner with Git, though i'm familiar with many of the basics and commands.

I have a project whose git history looks like this :

* a1b2c3 (HEAD -> main) Merged develop/new-update into main
|
|    * b2c3d4 (develop/new-update) Final commit on this branch, new work complete
|    |
|    Many other commits in between...
|    |
|    * c3d4e5 Starting new work
|   /
| /
* d4e5f6 Previous version, long ago

The latest commit a1b2c3 is the result of git checkout main then git merge--squashdevelop/new-update and git commit the staged collective changes of the other branch. Now, the state of the repo at the end of both branches is identical (git diff main develop/new-update has no output)


THE QUESTION

Now, when I pushed this to Github, it showed a "compare & pull request" notice, which confused me : Screenshot of pull request button on github website

If these branches' end states are identical, why it it asking me to pull request ? What would the pull request do to the repo if I created and accepted it ?

I noticed that the squash merge commit has only one parent commit, as if I directly wrote those changes while on the main branch (and the develop branch says X commits ahead, 1 commit behind main). Would the pull request make the develop branch 'point' back into main again ?

I've only used pull requests while collaborating on others' projects, say to merge a branch of my fork into the original one. I found this article about pull requests on your own repo, but it only talks about the uses, and googling about pull requests only brings up examples where there are branches with differences, yet to be merged; or different repos involved.

I'd appreciate any insights. Thank you !


Solution

  • First of all let's be clear: a squash merge is not any sort of a merge. It is, as you have already observed, the creation of a normal single-parent commit on the branch. The topology has no record that this commit "came from" develop/new-update in any sense.

    Second, a pull request is actually a merge request. It is a proposal to merge.

    Thus you are asking to merge a completely independent branch, develop/new-update, into main. Well, why not? They diverged long ago, at d4e5f6. They might represent two different histories since then.

    Moreover, keep in mind that:

    • It is legal to merge A into B even if they have zero diff, just as a way of joining the topologies. You might wish to do that.

    • You could, after forming the pull request, make more commits and push them. Now the branches would differ.

    So GitHub has no idea what your long term intentions are. So it is not going to deny you the possibility that you might want to start a pull request. If it is going to object, that will happen later in the process.