# Proposal: Allow Customization of Git Merge Commit Message Template

2 messages from 2024-12-05 to 2024-12-05. Participants: dangling ., brian m. carlson.
Thread: https://gitlist.dev/t/62603

## dangling ., 2024-12-05 17:00

Subject: Proposal: Allow Customization of Git Merge Commit Message Template
Message-ID: <DM4PR14MB4880061D71993B749F44F2EDA7302@DM4PR14MB4880.namprd14.prod.outlook.com>
URL: https://gitlist.dev/e/DM4PR14MB4880061D71993B749F44F2EDA7302%40DM4PR14MB4880.namprd14.prod.outlook.com

```
Hello Git mailing list,

I’d like to propose a feature to allow users to modify the default merge commit message template generated by `git merge`. Currently, when running:

ˋˋˋ
git merge --no-ff upstream/main
ˋˋˋ

Git produces a message like:
ˋˋˋsh
Merge remote-tracking branch 'upstream/main' into my-branch
ˋˋˋ

While informative, this message can be verbose and sometimes makes branch names difficult to fit within the recommended 52-character first line. Personally, I find a simplified format like this more concise and effective:
ˋˋˋsh
Merge upstream/main into my-branch
ˋˋˋ

Proposal:
Introduce an option (e.g., a configuration setting or CLI flag) that allows users to specify a custom merge commit message template. For example:

- A new configuration option:
  ˋˋˋsh
  [merge]
      messageTemplate = "Merge %s into %s"
  ˋˋˋ
  Here, `%s` placeholders could represent the source and destination branches, respectively.

- Alternatively, a command-line flag:
  ˋˋˋsh
  git merge --message-template="Merge %s into %s" upstream/main
  ˋˋˋ

Looking forward to your thoughts.

/k
```

## brian m. carlson, 2024-12-05 23:16

Subject: Re: Proposal: Allow Customization of Git Merge Commit Message Template
Message-ID: <Z1I0XzE6QWlsyZkH@tapette.crustytoothpaste.net>
URL: https://gitlist.dev/e/Z1I0XzE6QWlsyZkH%40tapette.crustytoothpaste.net
In-Reply-To: <DM4PR14MB4880061D71993B749F44F2EDA7302@DM4PR14MB4880.namprd14.prod.outlook.com>

```
On 2024-12-05 at 17:00:56, dangling . wrote:
> Proposal:
> Introduce an option (e.g., a configuration setting or CLI flag) that allows users to specify a custom merge commit message template. For example:
> 
> - A new configuration option:
>   ˋˋˋsh
>   [merge]
>       messageTemplate = "Merge %s into %s"
>   ˋˋˋ
>   Here, `%s` placeholders could represent the source and destination branches, respectively.

I think in general that such an option would need multiple placeholders.
Just because in English we place the name of the second head before the
name of the first head does not mean that that is true in all languages
or translations.

> - Alternatively, a command-line flag:
>   ˋˋˋsh
>   git merge --message-template="Merge %s into %s" upstream/main
>   ˋˋˋ

I think this can be done more generally with a `prepare-commit-msg`
hook:

----
#!/bin/sh

COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2

case "$COMMIT_SOURCE" in
 merge)
   /usr/bin/perl -i.bak -pe '
   s/Merge remote-tracking branch '\''(.*)'\''/Merge $1/
   ' "$COMMIT_MSG_FILE"
   ;;
 *) ;;
esac
----

That's the approach we would generally recommend here, since it's more
flexible and allows you more customization over the message.  Of course,
you can use sed or Ruby instead (or even ed or ex) if you prefer.
-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA

```
