Reading the docs doesn't tell me whether this can be done or not, which indicates to me it can't be done, but I want to check with some smarter people. I think it would be very helpful to indicate both a project template template = .git/gitmessage
and a global template template = ~/.gitmessage
to fallback to if the project one doesn't exist. I have tried adding 2 template
entries in ~/.gitconfig
and pointed one at a global template and one at a local template and that didn't work no matter what order I put them in.
Relevant documentation:
When editing the commit message, start the editor with the contents in the given file. The commit.template configuration variable is often used to give this option implicitly to the command. This mechanism can be used by projects that want to guide participants with some hints on what to write in the message in what order. If the user exits the editor without editing the message, the commit is aborted. This has no effect when a message is given by other means, e.g. with the -m or -F options.
Git has two kinds of configuration options: options which can have multiple values and options which can have at most one value. I believe that commit.template
is the latter.
The general pattern for options which take at most one value is that more narrowly scoped config files take precedence over more broadly scoped configuration files. That is, the .git/config
in the repository (the local file) takes precedence over ~/.gitconfig
(the global file), which in turn takes precedence over /etc/gitconfig
(the system file).
If you want to set this option globally, you can do that in your ~/.gitconfig
file and then set a project-specific option in the config file in the repository. That should override the value in your global file and therefore use the project-specific template. For projects which don't have their own template, you'll use the one defined in the global file.