DEV Community

Cover image for 🔥 How to merge a pull request
Andrei L
Andrei L

Posted on • Updated on

🔥 How to merge a pull request

There are some rules that are best to follow when merging a pull request.

When merging a pull request, GitHub offers 3 options:

  • Create a merge commit
  • Squash and merge
  • Rebase and merge

We should use each of them depending of the situation:

  • If PR has only one commit and commit explains well what was done use Rebase and merge
  • If PR has only one commit but commit does not explain exactly what was done use Squash and merge and add commit name that will explain more exactly what was done
  • If PR has more commits but they are intermediary (ex: fix style, add object, remove test ) also use Squash and merge and add a commit name that will group all commits in one
  • If PR has more commits but every commit has an explicit title what has been done, each commit is a single unit, then use Create a merge commit so each commit will be visible in default branch

If you want to read more about how to write correct commit messages, follow the link https://conventionalcommits.org

Cover Photo by pine watt on Unsplash

Top comments (3)

Collapse
 
sargalias profile image
Spyros Argalias

Wow. This is a really good strategy. Very nice tip, thanks! Squashing bad commits and commit messages sounds great as sometimes the source history for a branch is not useful anyway.

Usually my team aims for good commits like in your last point, but it doesn't always happen.

Collapse
 
iamandrewluca profile image
Andrei L

Check out this conventionalcommits.org

Collapse
 
sargalias profile image
Spyros Argalias

Thanks very much. That's already what I use ;). Highly recommended for everyone.