git
commit messages
merge conflicts
version control
software development

How to avoid Merge branch 'name_of_branch' in commit messages?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

The auto-generated message Merge branch 'name_of_branch' ... appears when Git creates an actual merge commit and fills in the default message for you. If you want to avoid those messages, the real question is whether you want to avoid merge commits entirely or keep the merge commit but supply a more useful custom message.

Avoid the Merge Commit With Fast-Forward Merges

If the target branch has not diverged, Git can often move the branch pointer forward without creating a merge commit at all.

bash
git switch main
git merge --ff-only feature/login-fix

With --ff-only, Git either fast-forwards or fails. No merge commit means no auto-generated merge message.

This is the cleanest answer when the history shape allows it.

Rebase Before Merging

If the branches have diverged but you still want a linear history, rebase the feature branch onto the target branch before merging.

bash
1git switch feature/login-fix
2git rebase main
3
4git switch main
5git merge --ff-only feature/login-fix

After the rebase, the merge can usually become a fast-forward. This avoids the merge-commit message because it avoids the merge commit itself.

Use a Squash Merge

If you want one final commit on the target branch instead of many feature-branch commits, use --squash.

bash
git switch main
git merge --squash feature/login-fix
git commit -m "Apply login fix and tests"

A squash merge does not create the default merge commit either. Instead, it stages the combined change and lets you write a normal commit message.

Keep the Merge Commit but Write Your Own Message

Sometimes you do want a true merge commit because it preserves branch structure. In that case, just provide a better message explicitly.

bash
git switch main
git merge --no-ff -m "Merge login fix with session timeout handling" feature/login-fix

This still creates a merge commit, but it replaces the generic Merge branch ... text with something more useful.

Pick the Right History Style for the Team

There is no single universally correct approach. The right choice depends on how your team uses Git history.

Common preferences are:

  • fast-forward only for the cleanest linear history
  • rebase plus fast-forward for feature branches
  • squash merges for compact review history
  • merge commits when branch structure is meaningful and worth preserving

The important thing is to choose intentionally instead of accepting the default message as if it were the only option.

Common Pitfalls

The biggest mistake is trying to hide the merge message while still creating unnecessary merge commits. If you do not want the message, often what you really do not want is the merge commit.

Another issue is rebasing shared branches without coordinating with other developers.

A third problem is using squash merges everywhere and then losing commit-by-commit detail that the team actually wanted to preserve.

Summary

  • The default Merge branch ... message appears only when Git creates a merge commit.
  • Use fast-forward merges when possible to avoid merge commits entirely.
  • Rebase before merging if you want a linear history.
  • Use --squash when you want one clean final commit.
  • If you keep the merge commit, pass -m and write a useful custom message. Clean history comes from choosing the right integration strategy, not from accepting whatever default text Git happened to generate. Once the team agrees on merge style, the noisy message problem mostly disappears by design. That is the cleaner long-term fix.

Course illustration
Course illustration

All Rights Reserved.