In this video, you pictured your first pull request, format-and-lint with its four commits, merged with each of GitHub’s three merge buttons. You saw why git branch -d refused to delete your branch after the squash merge, even though GitHub said Merged. In the video, the letters A to D stand in for the ids of your branch’s four commits. Here are the key points:
-
Every commit has its own id, the hash that
git logshows. Two commits with the same message and the same changes are still two different commits if their ids differ. -
Create a merge commit keeps your commits as they are. GitHub adds a merge commit to
mainwith two parents: the last commit ofmainand your branch’s last commit. It makes that merge commit even whenmaindidn’t move and a merge on your laptop would have been a fast-forward. -
Squash and merge makes one new commit. It holds the changes of all four commits, has one parent, and takes the pull request’s title as its message. Your four commits aren’t in the history of
mainat all. -
Rebase and merge copies your commits onto the tip of
main, one by one, without a merge commit. The copies have the same messages and the same changes, but every copy is a new commit with a new id. GitHub makes new copies even whenmainhasn’t moved. -
Here,
git branch -dlooks for your branch’s own commits in the history ofmain. That’s onmain, after you’ve deleted the branch on GitHub, rungit pulland rungit fetch --prune. Git compares ids, not messages. After a merge commit, the commits are there, so the branch is deleted without complaint. After a squash or a rebase merge, they aren’t, even though all your work is inmain.
This is what git branch -d says after each button, once the branch is deleted on GitHub and you’ve run git pull and git fetch --prune on main. After Create a merge commit, it deletes the branch, and … stands for your branch’s last commit id:
$ git branch -d format-and-lint
Deleted branch format-and-lint (was …).
After Squash and merge or Rebase and merge, it refuses, starting with this line: