Skip navigation
Git Merge vs. Rebase vs. Squash Commit
0:00 / 1:27

Git Merge vs. Rebase vs. Squash Commit

Sahn Lam

@sahnlam48K followers

Visit on X
1,222 likesDownloadOriginal post

65,251 views

Git Merge vs. Rebase vs. Squash Commit What are the differences and when should you use each? As I explain in more detail in the video, there are some key distinctions. Git Merge This creates a new commit in the target branch. The new commit ties the histories of both main and feature branches together. Git merge is non-destructive - it introduces a new commit without altering existing ones. Git Rebase Rebase transplants commits to the tip of another branch. It creates new commits for each one moved over. The benefit is linear history. But be cautious with shared branches to avoid confusing collaborators. Squash Commit Squashing condenses multiple commits into one, streamlining the commit history. Watch the video to see when to use merge vs rebase vs squash when incorporating changes between main and feature branches. – Subscribe to our weekly newsletter to get a Free System Design PDF (158 pages):

5 Comments

Comments from the original post on X (Twitter)

  • deepPurple's profile picture

    @deepestpurplest

    I tried git rebase and end up with unresolved merges (shared project) which doesn’t let me checkout to feature branch with some weird messages like currently rebasing cannot checkout. What am I doing wrong 😑

    2 likes

  • Abdellah's profile picture

    @abdel_ramadhan

    I contributed to one popular library and the maintainer asked me to do a rebase. It wasn't easy to do because this is a feature of git I have never used it. So, he finally did the rebase for me. This is beneficial content. Please where can more of it be found?

    2 likes

  • Deisbel (Sr. Software Developer)'s profile picture

    @deisbel

    Good details. Thank you for sharing them. One thing, In 20+ years I have never needed to do a Rebase. I wonder how many of you out there have done anything different of a git merge?

    1 like

  • Who Am I's profile picture

    @whoami405

    +

  • Python Space's profile picture

    @python_spaces

    Very well explained with great visuals. 🙏