2

I renamed my local branches to shorter names which works fine except when doing a merge.

The commit message automatically created for merges uses my local shortened name.

Merge branch 'shortname' into this-branch

This name is only for my convenience, so I would like to use the remote branch name in the commit log (so we don't have every developers branch abbreviations showing up in the commit logs).

Is there a way to configure git to do this?

ideasman42
  • 42,413
  • 44
  • 197
  • 320
  • There's no easy way because all Git is doing is using the supplied string from the command line here. You can, however, either edit the message manually, or write a `prepare-commit-msg` hook. Since such a hook is a program entirely of your own devising, you can make it do anything you want. See [the githooks documentation](https://www.kernel.org/pub/software/scm/git/docs/githooks.html) for details on Git hooks. – torek Jun 12 '17 at 05:37

1 Answers1

2

Adding to the idea of a local hook, you can:

That way, the process is automated and can retrieve the original name of the branch.

An alternative approach, which would use no hooks, would be to define the git-commit-template in a git merge wrapper script. See for instance this answer.
Again, you could get the original name from the branch description, but this time inject it in the merge commit message template.


Note that, with Git 2.28 (Q3 2020), you cannot edit the description and set the upstream branch at the same time.

See commit dc44639, commit 6b70930, commit 6d504d5 (15 Jun 2020) by Denton Liu (Denton-L).
(Merged by Junio C Hamano -- gitster -- in commit 7b2685e, 25 Jun 2020)

branch: don't mix --edit-description

Signed-off-by: Denton Liu

git branch accepts --edit-description in conjunction with other arguments. However, --edit-description is its own mode, similar to --set-upstream-to, which is also made mutually exclusive with other modes.
Prevent --edit-description from being mixed with other modes.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250