How to use Git's default commit message when resolving merge conflicts?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When Git stops on a merge conflict, it already prepares a default merge commit message for you. If you want to keep that generated message, the key is simple: finish resolving the merge and commit without supplying your own -m message.
How Git Stores the Default Message
During a merge conflict, Git writes a prepared message into its merge state. After you resolve conflicts and stage the files, a normal git commit uses that prepared merge message as the starting point in your editor.
A typical workflow looks like this:
At the git commit step, Git opens your editor with the generated merge message. You can keep it, edit it, or save it unchanged.
Use the Default Message Without Opening an Editor
If you want Git's generated message exactly as-is, use:
This tells Git to reuse the prepared merge message and skip the editor entirely. It is the most direct answer to "use Git's default commit message when resolving merge conflicts."
What Not to Do
If you run:
you replace the prepared merge message with your own text. That is fine if you want a custom message, but it is not how you keep Git's default one.
Likewise, if conflicts are not fully resolved or staged, Git will refuse to create the merge commit. The prepared message exists, but the merge cannot finish until the index is clean enough.
Check Merge Status Before Committing
A quick git status helps confirm what is still unresolved.
You want to see that all conflicted files have been fixed and staged. If Git still reports "both modified" or "unmerged paths," you are not ready for the final commit yet.
Why the Default Message Can Be Useful
Git's generated merge message already includes the context of the merge, usually something like merging one branch into another. For routine merges, that is often enough. It preserves the fact that this was a merge commit rather than a normal single-parent commit.
Many teams are happy with the default message because:
- it is consistent
- it records the source branch
- it avoids unnecessary hand-written noise
If the conflict resolution involved a notable decision, you can still open the editor with plain git commit and add a short explanation below the generated first line.
Merge Commit Versus Rebase Conflict
Be careful not to mix this up with rebase conflicts. A merge conflict during git rebase uses different continuation commands and a different state machine. The idea of a prepared message still exists in Git workflows, but the command you run to continue is not the same.
This article is specifically about merge conflicts that end in a merge commit.
Common Pitfalls
- Using
git commit -m ...and accidentally overriding the generated merge message. - Forgetting to stage the resolved files before committing.
- Assuming
git commit --no-editcan work while unmerged paths still exist. - Confusing a merge conflict with a rebase conflict and using the wrong continuation flow.
- Editing the merge message template carelessly and deleting useful context about the merged branch.
Summary
- After resolving conflicts, stage the files and run
git committo use Git's prepared merge message. - Use
git commit --no-editif you want the default message unchanged. - Do not pass
-mif your goal is to keep Git's generated message. - Check
git statusfirst to make sure all conflicts are resolved. - The default merge message is often sufficient and preserves useful context automatically.
Related reading
- How to use Merge layer concat function on Keras 2.0.0?
- How to use Rabbit inside a gitlab-ci.yml file?
- How to use submodules publicly, but symlinks to a single clone locally?
- How to version control a source code which communicates with database?
- How to view diff of a forked github project
- How to view file diff in git before commit
- How to 'Watch' only a directory in a GitHub repository?
- How would Git handle a SHA-1 collision on a blob?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.