What this error means and why Git shows it

This error appears when you run git commit during a merge and Git expects you to provide a merge commit message using the -m flag, but you did not include one. Git is telling you that you are in the middle of merging two branches, and it needs you to be explicit about the message for this merge commit.

The full error usually reads something like: "error: is a merge but no -m option was given." This happens because Git's default behavior changed in recent versions. Older versions would open your text editor automatically to let you write a message. Now, Git requires you to either use -m to provide the message on the command line, or use --no-edit to accept the default merge message without editing it.

You are not stuck — this is a safety feature. Git wants to make sure you intentionally complete the merge and know what message will be recorded in your history.

Key Takeaways

  • The error occurs because you ran git commit during a merge without telling Git how to handle the commit message.
  • Use git commit -m "Your merge message here" to complete the merge with a custom message.
  • Use git commit --no-edit to complete the merge with Git's default merge message.
  • If you have not resolved merge conflicts yet, run git status first to see which files still need attention.
  • You can abort the entire merge at any time with git merge --abort if you want to start over.

The two fastest ways to fix this right now

If you have already resolved all merge conflicts (or there were none), you have two options depending on whether you want to write a custom message or use Git's default.

Option 1: Complete the merge with a custom message. Run this command, replacing the text in quotes with your own message:

git commit -m "Merge branch 'feature-name' into main"

This tells Git to finish the merge and record your message in the commit history. The message should describe what you are merging and why. A simple format is "Merge branch 'branch-name' into target-branch".

Option 2: Complete the merge with Git's default message. Run this command:

git commit --no-edit

Git will automatically generate a message like "Merge branch 'feature-name' into main" and complete the merge without opening an editor. This is faster if you do not need a custom message.

What to do if you still have merge conflicts

Before you run either commit command above, check whether all conflicts are actually resolved. Run git status to see the current state of your merge.

If you see files listed under "both added", "both modified", or "both deleted", those are unresolved conflicts. Open each one and look for conflict markers — lines that look like this:

<<<<<<< HEAD your version of the code ======= the other branch's version >>>>>>> branch-name

Delete the conflict markers and the code you do not want to keep, leaving only the version you need. Then save the file. Repeat for every conflicted file. Once all conflicts are resolved, run git add . to stage the resolved files, and then use one of the commit commands from the section above.

How to abort the merge and start over

If you want to cancel the entire merge and go back to the state before you started, run git merge --abort. This will undo all merge changes and put you back on your original branch as if the merge never happened.

This is useful if you realize the merge was a mistake, or if you want to resolve conflicts differently. After aborting, you can try the merge again later, or switch to a different branch entirely.

Why Git changed this behavior

Older versions of Git would open your default text editor (like Vim or Nano) automatically when you tried to commit a merge without a message. This meant you had to know how to exit the editor, which confused many people. Newer versions of Git require you to be explicit about the message instead, which prevents accidental commits and makes the process clearer.

If you want to restore the old behavior where Git opens an editor automatically, you can configure Git to do so by running git config core.editor "your-editor-name" and then using git commit without -m. However, most teams now prefer the explicit -m approach because it is faster and leaves less room for confusion.

Common mistakes that lead to this error

The most common mistake is forgetting that you are in the middle of a merge. If you have just run git merge branch-name and then immediately run git commit without any flags, Git will show this error. Always check your branch status with git status before committing — it will tell you if you are in a merge state.

Another mistake is trying to use git commit without any message flag at all, expecting an editor to open. In recent Git versions, this does not happen during merges. You must use either -m or --no-edit.

A third mistake is running git commit -m without actually providing a message. The command needs text after -m in quotes, like git commit -m "your message". If you forget the quotes and message, Git will wait for input or show an error.

Frequently Asked Questions

Can I edit the merge message after I have already committed it?

Yes, but only if you have not pushed the commit to a shared repository yet. Run git commit --amend -m "new message" to change the most recent commit message. If you have already pushed, changing the message requires force-pushing, which can cause problems for other people using the repository.

What is the difference between -m and --no-edit?

The -m flag lets you write a custom message on the command line. The --no-edit flag uses Git's automatically generated merge message without letting you change it. Use -m if you want to explain why the merge happened; use --no-edit if the default message is fine.

Do I have to resolve all conflicts before committing the merge?

Yes. Git will not let you complete the merge until every conflicted file has been resolved and staged with git add. If you try to commit before resolving conflicts, you will get an error telling you which files still need attention.

What happens if I abort the merge by mistake?

Nothing is lost. You are still on the same branch with the same files. You can run git merge branch-name again to start the merge over from the beginning. All your work is safe.

Can I use a multi-line message with -m?

Yes. Use multiple -m flags, like git commit -m "First line" -m "Second line". Each -m becomes a separate paragraph in the commit message. This is useful for writing a summary line followed by more details.