Watch on YouTubePlayPlays from YouTube. Google's privacy policy (opens in a new tab) applies.
Adam explains GitHub's three ways to merge a pull request (merge commit, squash and merge, rebase and merge) and why he prefers squash, then squash-merges his first PR by hand on GitHub.
What you'll learn
- GitHub offers three ways to merge a PR; teams differ in which they use.
- Create a merge commit (GitHub's default): all the branch's commits stay in
main's history, plus a commit saying the branch was merged. - Squash and merge: all commits become one on
main("we added My bookings"); the detail stays on the feature branch. - Rebase and merge: the commits appear as if made on
maindirectly; the branch's existence is lost from history. - For a tidy history, squash and merge.
- If you just ask Claude to "merge the PR", it may choose the default; put your preference in the shared CLAUDE.md, or restrict merge types in GitHub's repo settings.
- The squash confirmation screen lets you edit the commit title and extended description.
Chapters
- 00:00Merge commit, GitHub's default
- 02:10Squash and merge
- 03:31Rebase and merge
- 05:01Choosing your team's merge type
- 06:35Squash-merging your first PR
- 00:01Okay, designers. Well, the time has come to merge this PR once and for all.
- 00:08But you didn't think it's going to be that easy now, did you?
- 00:12It is easy, of course, but I think it's important for us to like just quickly skim through the three ways to do it.
- 00:19we are going to use just one way but I think you know it it helps to know that there are three ways basically to do it because you know
- 00:26depending on uh you know what kind of engineering team you'll end up working with uh you might see you know different strategies uh for merging PRs okay so let's
- 00:35just really quickly skim over those okay um so the first kind of PR and I think the one that GitHub uh will uh present to you as the default
- 00:46one is called emerge merge uh PR.
- 00:50Is it merge PR?
- 00:51No, it's a merge commit PR.
- 00:53Okay. So, what we do is we basically like all of the comments which we just did, right?
- 00:58uh the ones about um you know the fixes and you know the refinements and everything along the way it all gets like saved within this history of the main
- 01:11branch along with one new information about like hey this is where we decided to take this branch and merge it with the new one.
- 01:18Okay. So like further down the line if you want to go go back to like the history uh you will find basically uh a trace of every single thing
- 01:29you did when you were working on that PR and you know if you are really attached about like to your work and uh you it's it's really important for
- 01:38for you and for the entire world to see just how much effort you have put into like making that my bookings view come alive.
- 01:47that might be an option for you because this way all of the commits are you know preserved along like with the history of the main branch along with the
- 01:56information that uh you know at some point these commits were part of a different branch and they were just merged into this one.
- 02:03Okay. So if we were if we were to actually do this kind of a merge that graph which we had in clot code it would look exactly like this.
- 02:11There would be that additional line.
- 02:12Okay. There is a second version.
- 02:15It's called squash and merge.
- 02:18And I've just realized it's I I think it's impossible to say the word squash and not do this gesture with your hand.
- 02:25So it's the squash and merge.
- 02:27So how is this different from the merge commit PR?
- 02:31So squash and merge will basically take all of your commits and is going to squash them into just one.
- 02:38So that you know whoever is looking at the history of commits or just the history of the main branch the only thing that this person is going to see
- 02:46is that at this point in time we've just added the my bookings view but this person unless you know unless they are going to deliberately switch into that feature
- 02:54branch which we've been working on.
- 02:57They are not going to learn about the fact that you know we did some sort of simplification pass um that we did refine the my viewing my viewing my
- 03:07my my [laughter] bookings empty states at some point and that this wasn't part of the first implementation you know that too many can be considered noise.
- 03:17So a squash and merge is a perfect way to cut away the noise and just preserve the only thing that matters which is hey at this point in time
- 03:26we just rolled out the my bookings view.
- 03:28Okay. And then there's the third way which is uh it's the rebase and merge.
- 03:35So rebase and merge.
- 03:37What it does is um it's going to take all of your commits which we did uh as part of this branch and it's going to rebase them so that
- 03:46they appear as they were made on the main branch and the history or that the fact about the branch you know existing is sort of lost.
- 03:54Okay. So it's going to look like as as if we were just committing directly to the main branch from the very beginning.
- 04:01And this is going to again preserve all of the information about the work we did like you know the fact that we did again the empty states refinements or
- 04:10that we did simplification pass.
- 04:12So it's really similar to the first one except on the first one you know with the um with the merge commit we are going to preserve the fact that
- 04:21this work once lived on a different branch.
- 04:25So if like keeping up your work and like everything that you did along the way is important to you, consider one or two, preferably one.
- 04:34But what I'm going to go with and I what I would recommend and I believe this might be a little bit of a consensus or although maybe I shouldn't
- 04:43go really that far.
- 04:44If you really care about like having a like a tidy version history, I think you should consider the squash.
- 04:51I'm sorry, the squash and merge.
- 04:54Okay, so we are going to do the squash and merge commit.
- 04:57Now there are a couple of ways of to do it.
- 04:59Of course, um as with everything you can either go back to GitHub, okay, open up this PR and you can scroll down over here and over here where it
- 05:08says merge pull request, you can open this up to see all of the three options to merge a PR which we've just discussed, right?
- 05:16And you can see that this by like by default it's going to create that merge commit.
- 05:20Okay, merge commit again being uh being this.
- 05:24This is the merge commit.
- 05:26What I want to do is I want to do squash and merge.
- 05:30Now, if I were to go back to claude and ask it to um ask it to merge the PR.
- 05:37Oh, it even suggests uh uh this as the next message.
- 05:42You know, truth be told, I have no idea what Claude is going to do.
- 05:45Uh but I have um I I suspect it's going to go with also the merge commit option.
- 05:52Okay. Uh if you want your clot to always do squash and merges, this is something you would want to input in your CLAUDE.md file, the one that uh
- 06:02gets shared with everyone else in your main uh in your main project folder.
- 06:09So this CLAUDE.md file, right?
- 06:10this is the right place for you to uh have this information about you know hey in this repo we prefer the squash and merge.
- 06:20There is also an option on GitHub in your repo settings to set it up so that you basically have no other option to do a squash and merge.
- 06:28Okay, if you really want to go uh like allin uh that would be probably an option for you.
- 06:35So are we going to ask CL or are we going to do it ourselves?
- 06:38Of course, we're going to do it ourselves because this is the first PR and I think it's important to, you know, uh, witness this firsthand, like the the feeling
- 06:47and the the sensation of merging your first PR manually on GitHub.
- 06:53So, I hope you're with me right now as I'm going to open up this drop down.
- 06:57I'm going to select the squash and merge.
- 07:00I'm going to take a deep breath in.
- 07:06[snorts] For the last time, I'm going to do this with my hand.
- 07:10As I click and I do squash and mer.
- 07:13Okay, there is a confirmation screen.
- 07:16Uh, you can add some sort of descriptions.
- 07:18Basically, this is going to this is how your comment message is going to look like.
- 07:22So, a comment message can have a title and then it has it also has a body or extended description in that in that uh particular example.
- 07:30Um so basically what we are now uh describing or setting up is how this commit is going to look like.
- 07:37Okay. Um and I'm just going to go with the defaults.
- 07:40So again I'm going to do this with my hemp and I'm going to do confirm squash and merge.
- 07:51Okay. Hopefully my internet doesn't break right now.
- 07:54That would be really bummer.
- 07:56that would really ruin all of the like this dramatic ending and it appears this is going to be the case here.
- 08:03Uh such an unfortunate turn of events.
- 08:09Well, in our imagination we can imagine like that this internet connection is flawless and that in a second we are going to see a confirmation message of our PR
- 08:20being successfully merged. Or maybe I'll just use the magic of editing.
- 08:26Just like that. Okay.
- 08:28And we have like officially merged our PR.
- 08:31Congratulations. Congratulations. Uh okay.
- 08:34I'll see you in the next lesson in which we are going to step it up a little.