Home > Net >  Why local git repo does not see the merge executed on origin?
Why local git repo does not see the merge executed on origin?

Time:04-03

I created a pull request on branch "feature/90...".
I merged it in GitHub to the master branch (named "main").
[UPDATE: I used the "Squash and Merge" functionality in GitHub pull request page]

enter image description here

The branch is not deleted.
On VS Code I can switch to master and fetch master from origin.
Why I don't see teh merge in VS Code "GitGraph" plugin and neither on SourceTree?

enter image description here

enter image description here

Also fetching/pulling from bot hbranches does not change it, the "merge to master" line is not represented.
To see it I can merge the branch to master also locally and this is the result:
(ignore the extra "clenup" commit on master branch)

enter image description here

Is it possible to have the merge operation executed on the origin also "visible"/"replicated" on the local repository copy?
Why the pull/fetch does not show it?

[UPDATE]
Seems like the "Squash and Merge" operatin in GitHub pull request is not executing a git merge ("Create a Merge commit" does) despite the description does not give an hint about it:
enter image description here

CodePudding user response:

It's because what you did on GitHub was not a merge. You did a "Squash and merge" instead. (I know that from looking at the screenshot in your other question on this topic.)

GitHub offers three ways to accept a pull request: Merge, Rebase and Merge, and Squash and Merge. The second two, despite the name, are not merges. They do create a new commit on main, which I can actually manage to see in your annoyingly blanked out diagrams; but they do not result in a merge topology (a commit with two parents) which is what you are looking for (and which is what you created on local when you performed a true merge locally).

If you wanted a merge topology you should have asked GitHub to do a true Merge. However, many companies do not allow this; they configure GitHub to do a Squash and Merge instead. That's okay, but then you must not look for merge topology. That topology is exactly what Squash and Merge is designed to avoid.


(Incidentally, you should have deleted your feature branch. A PR branch that is closed by Squash and Merge is useless and should be deleted immediately. Otherwise there is a danger that you might try to add more commits to it and try to Squash and Merge it again, which will result in horrible merge conflicts and other nasty side effects.)

  • Related