Muslim
Why I stopped pressing github merge button

Why I stopped pressing github merge button

2 min read

THE ART OF MERGING

Keeping your project's commit history clean and concise is essential for maintaining clarity and ease of navigation. Inspired by Linus Torvalds and the Linux community, who avoid using GitHub's blue merge button, I decided to adopt a similar approach. This guide will walk you through the process step-by-step.

Why Merge Locally?

Merging PRs locally gives you more control over the commit history and allows you to ensure that the merge process aligns perfectly with your workflow. This is particularly useful when dealing with complex projects that require precise version control.

Step-by-Step Guide

Option 1: Squashing Commits

1. Fetch the Latest Changes

Start by fetching the latest changes from your remote repository to ensure you're working with the most up-to-date data.

git fetch origin

2. Checkout to Your Target Branch

Switch to the branch you want to merge the changes into (e.g., main or master).

git checkout main

3. Merge the PR Branch Using Squash

Use the --squash option to combine all the commits from the PR branch into a single commit.

git merge --squash <branch name>

# Commit the squashed changes without creating a new commit message. 
# --no-edit option ensures that the original commit message is used.

git commit --no-edit

OR

# If you don't want to change commit message
# This will not squash or change commit message

git merge <branch name>

OR

Use the --no-commit option to merge the changes and prepare for a custom commit message.

git merge --no-commit origin/renovate/typescript-5.x-lockfile
git commit

3. Push the Changes

Finally, push the merged changes to your remote repository.

 git push origin main

Benefits of These Approaches

- Clean Commit History: Merging with squash keeps your commit history concise and easy to understand.

- Flexibility: The option to customize commit messages ensures that you can keep necessary commit details without additional merge messages.


Inspired by Linus Torvalds's practice of avoiding GitHub's blue merge button [Reference](https://youtube.com/clip/Ugkx9kTm-lSdwPE2Favn1KrnPYiOucdhXcFH?si=VyKUrS2V12ZQXMfU)

I have been tasting this [here](https://github.com/musllim/express-starter) on my express starter template

HAPPY CODING