threads / discuss / 62603

Proposal: Allow Customization of Git Merge Commit Message Template

Subject: Proposal: Allow Customization of Git Merge Commit Message Template

## tl;dr

2 messages between Dec 5, 2024 and Dec 5, 2024.

replies: 1people: 2as markdown or json

dangling .· Dec 5, 2024, 17:00 UTC · lore
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· Dec 5, 2024, 23:16 UTC · re: dangling . · lore

Re: Proposal: Allow Customization of Git Merge Commit Message Template

On 2024-12-05 at 17:00:56, dangling . wrote:
Show 9 quoted lines
> 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

← back to recent threads