Just pass the -m and --no-ff parameters to the merge command:

$ git merge other-branch -m "Commit Message" --no-ff

The --no-ff parameter is required to prevent merging as a fast-forward without merge commit.

Answer from Joe Zim on Stack Overflow
Top answer
1 of 6
129

Just pass the -m and --no-ff parameters to the merge command:

$ git merge other-branch -m "Commit Message" --no-ff

The --no-ff parameter is required to prevent merging as a fast-forward without merge commit.

2 of 6
20

You basically have two option.

Easy solution: don't merge, Rebase
Rebase your branch on top of the main branch, resolve conflict, and then merge. As you'll have a straight history, you'll be able to fast-forward to merge and this won't create any merge commit.

git checkout feature
git rebase main
# Resolve conflict if there is
git checkout main
git merge feature

Second option: Rebase -i
You can edit your history after your merge (before you push to a remote). You can manage this with rebase interactive mode.

git checkout main
git merge feature
#You merge and resolve conflict
git rebase -i <sha of the commit before the merge>

Then you'll be taken into an interactive shell with the list of the commits, e.g.:

pick 73c991e Create progress bar module
pick b8a0b83 merge branch feature
pick 2120f47 Add user form
pick 70c55e4 Quiz prototype system

You just need to add squash or s instead of pick:

pick 73c991e Create progress bar module
pick b8a0b83 merge branch feature
s 2120f47 Add user form
pick 70c55e4 Quiz prototype system

This command would squash together b8a0b83 and 2120f47. The next step will be a commit text editor where you have both commit message combined, and it's now up to you to edit them correctly to only keep your original message.

🌐
Git
git-scm.com › docs › git-merge
Git - git-merge Documentation
This option can be used to override ... configuration variable to enable this by default exists or will be added. ... Set the commit message to be used for the merge commit (in case one is created)....
Discussions

bash - Automate "git merge" commit message - Stack Overflow
If --log is specified, a shortlog of the commits being merged will be appended to the specified message. The git fmt-merge-msg command can be used to give a good default for automated git merge invocations. The automated message can include the branch description. — git docs ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with ... More on stackoverflow.com
🌐 stackoverflow.com
macos - Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch - Stack Overflow
For some reason my default editor ... to command and write ":wq" as in vim, not sure if nano even supports this. ctrl + x and ctrl + c worked in my case, Ubuntu 20 2023-02-16T08:05:06.053Z+00:00 ... Save this answer. ... Show activity on this post. Instead, you could git CtrlZ and retry the commit but this time add " -m " with a message in quotes ... More on stackoverflow.com
🌐 stackoverflow.com
how can I customize git's merge commit message? - Stack Overflow
Perhaps a comment with a link to the question that is similar but different would be a better idea. 2017-09-12T08:57:06.38Z+00:00 ... Looks like as of version Git 1.7.8 you can do git merge --edit ... to specify the commit message. And as of 1.7.10, dropping into edit mode will be the default behavior · From this release on, the "git merge" command ... More on stackoverflow.com
🌐 stackoverflow.com
Git: How to edit/reword a merge commit's message? - Stack Overflow
Since commit dd6fb00 ("rebase -p: ... commit message of the merge commit being rebased is passed to the merge command using a subshell executing 'git rev-parse --sq-quote'. Double quotes are needed around this subshell so that, newlines are kept for the git merge command. ... With Git 2.23 (Q2 ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Brandon Pugh's Blog
brandonpugh.com › posts › tips for creating merge commits
Tips for creating merge commits | Brandon Pugh's Blog
August 31, 2024 - While I personally prefer to rebase branches, one advantage of merging is that it’s easier to see how any conflicts were handled. If there were conflicts during the merge, then git will list the files in the commit message, but they’re commented out by default:
🌐
Git
git-scm.com › book › en › v2 › Git-Branching-Basic-Branching-and-Merging
Git - Basic Branching and Merging
Merge branch 'iss53' Conflicts: index.html # # It looks like you may be committing a merge. # If this is not correct, please remove the file # .git/MERGE_HEAD # and try again. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message ...
Find elsewhere
🌐
Linux Kernel
kernel.org › pub › software › scm › git › docs › git-merge.html
git-merge(1)
July 14, 2025 - This option can be used to override ... configuration variable to enable this by default exists or will be added. ... Set the commit message to be used for the merge commit (in case one is created)....
🌐
30 Seconds of Code
30secondsofcode.org › home › git › repository › merge branch
Merge a branch in Git - 30 seconds of code
May 26, 2023 - # Syntax: # git checkout <target-branch> # git merge --no-ff -m <message> <source-branch> git checkout master git merge --no-ff -m "Merge patch-1" patch-1 # Merges the `patch-1` branch into `master` and creates a commit # with the message "Merge ...
🌐
Linux Man Pages
linux.die.net › man › 1 › git-merge
git-merge(1) - Linux man page
Set the commit message to be used for the merge commit (in case one is created). The git fmt-merge-msg command can be used to give a good default for automated git merge invocations. ... Allow the rerere mechanism to update the index with the result of auto-conflict resolution if possible.
🌐
Git
git-scm.com › docs › git-fmt-merge-msg
Git - git-fmt-merge-msg Documentation
Takes the list of merged objects on stdin and produces a suitable commit message to be used for the merge commit, usually to be passed as the <merge-message> argument of git merge. This command is intended mostly for internal use by scripts automatically invoking git merge.
🌐
Git Examples
gitexamples.com › manual › merge
git-merge - man page
As that is a very rare occasion, no configuration variable to enable this by default exists or will be added. Set the commit message to be used for the merge commit (in case one is created).
🌐
Git Scripts
gitscripts.com › git-merge-save-commit-message
Git Merge: Save Your Commit Message Like a Pro
July 27, 2025 - When merging branches in Git, you can save a commit message using the `-m` option followed by your message to describe the changes made during the merge. git merge feature-branch -m "Merged feature-branch into main" Git merge is the process ...
🌐
Git Scripts
gitscripts.com › git-merge-commit-message
Mastering Git Merge Commit Message Basics
December 8, 2025 - A git merge commit message is a log entry created when merging branches, detailing the changes that were integrated, and can be written using the `-m` option to specify a custom message. git merge feature-branch -m "Merged feature-branch into ...
Top answer
1 of 8
279

If you add the --preserve-merges option (or its synonym, -p) to the git rebase -i command then git will try to preserve the merges when rebasing, rather than linearizing the history, and you should be able to amend the merge commits as well:

git rebase -i -p HEAD~5

Note. --perserve-merges has been deprecated in favour of --rebase-merges as of git v2.22 (https://www.infoq.com/news/2019/07/git-2-22-rebase-merges/).

2 of 8
41

Note that, starting git1.7.9.6 (and git1.7.10+), git merge itself will always trigger the editor, for you to add details to a merge.

"git merge $tag" to merge an annotated tag always opens the editor during an interactive edit session. v1.7.10 series introduced an environment variable GIT_MERGE_AUTOEDIT to help older scripts decline this behaviour, but the maintenance track should also support it.

It also introduces an environment variable GIT_MERGE_AUTOEDIT to help older scripts decline this behavior.

See "Anticipating Git 1.7.10":

Recently in a discussion on the Git mailing list, Linus admitted (and I agreed) that this was one of the design mistakes we made early in the history of Git.
And in 1.7.10 and later, the git merge command that is run in an interactive session (i.e. both its standard input and its standard output connected to a terminal) will open an editor before creating a commit to record the merge result, to give the user a chance to explain the merge, just like the git commit command the user runs after resolving a conflicted merge already does.

Linus said:

But I don't really care deeply how it actually works - my main issue is that git makes it way too easy to have bad merge messages.
I think part of that is an even simpler idiocy: we never even fire up the editor by default for a "git merge", but we do for a "git commit".
That was a design mistake, and it means that if you want to actually add a note to a merge, you have to do extra work. So people don't
.


Note that, before Git 2.17 (Q2 2018), "git rebase -p" mangled log messages of a merge commit, which is now fixed.

See commit ed5144d (08 Feb 2018) by Gregory Herrero (``).
Suggested-by: Vegard Nossum (vegard), and Quentin Casasnovas (casasnovas).
(Merged by Junio C Hamano -- gitster -- in commit 8b49408, 27 Feb 2018)

rebase -p: fix incorrect commit message when calling git merge.

Since commit dd6fb00 ("rebase -p: fix quoting when calling git merge", January 2018, Git 2.16.0-rc2), the commit message of the merge commit being rebased is passed to the merge command using a subshell executing 'git rev-parse --sq-quote'.

Double quotes are needed around this subshell so that, newlines are kept for the git merge command.

Before this patch, following merge message:

"Merge mybranch into mynewbranch

Awesome commit."

becomes:

"Merge mybranch into mynewbranch Awesome commit."

after a rebase -p.


With Git 2.23 (Q2 2019), A "merge -c" instruction during "git rebase --rebase-merges" should give the user a chance to edit the log message, even when there is otherwise no need to create a new merge and replace the existing one (i.e. fast-forward instead), but did not.
Which has been corrected.

See commit 6df8df0 (02 May 2019) by Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit c510261, 13 Jun 2019)

🌐
Dribin
dribin.org › dave › blog › archives › 2018 › 10 › 21 › git-merge-commit-message
git Merge Commit Messages | Dave Dribin’s Blog
October 21, 2018 - But if you just accept the defult message, the real commit message will be: % git log -1 commit 86cb4bbcc5f2ed54641a0f2a58a4b03bb73be0a3 (HEAD -> master) Merge: efd152d 474a8f4 Author: Dave Dribin <dave@example.com> Date: Fri Oct 19 23:38:47 2018 -0500 Merge branch 'branch' It stripped every line with the comment prefix, so you get a nice short message.