Skip to content

Instantly share code, notes, and snippets.

@emmanuelnk
Created August 25, 2022 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmanuelnk/a742769e9794d2c40295a59d5ac20674 to your computer and use it in GitHub Desktop.
Save emmanuelnk/a742769e9794d2c40295a59d5ac20674 to your computer and use it in GitHub Desktop.
git merge vs git merge --squash vs git rebase

Let's start by the following example:

enter image description here

Now we have 3 options to merge changes of feature branch into master branch:

  1. Merge commits
    Will keep all commits history of the feature branch and move them into the master branch
    Will add extra dummy commit.

  2. Rebase and merge
    Will append all commits history of the feature branch in the front of the master branch
    Will NOT add extra dummy commit.

  3. Squash and merge
    Will group all feature branch commits into one commit then append it in the front of the master branch
    Will add extra dummy commit.

You can find below how the master branch will look after each one of them.

enter image description here

In all cases:
We can safely DELETE the feature branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment