git config commit.template apparently not working
Asked by p4010:

I have set a local commit.template in a git repo I manage with SourceTree. When I commit as 'git commit -a', I get a vi editor with the template file (a hidden file in repo root) correctly loaded, as expected. But SourceTree seems to ignore it, and the commit sheet presents an empty commit text area.

Is there a way to have a commit template in SourceTree?


Answers:
author: Carl Menezes
body: Same problem here. Windows 7, Sourcetree 1.6.8.0, Git 1.9.4

I'm on Windows and I followed the exact same steps you did, @Kieran Senior \[Atlassian\]. I just omitted $HOME (but still used a relative path), because I wanted my commit template to be specific to my repository and I want it to propagate to other team members, just like my .gitignore file.

Here are my steps:

1. Open Sourcetree and go to the repository.
2. Click the terminal button. Entered these commands:
   1. touch .committemplate.txt
   2. vi .committemplate.txt
   3. Added the words "test template", saved and closed the file.
   4. git config commit.template .committemplate.txt
3. Closed the terminal and back to Sourcetree. It now showed .committemplate.txt as an unstaged file with the contents "test template".
4. Clicked the Commit button.

++Expected:++

The words "test template" somewhere in the commit message text area.

++Actual++

The commit message text area was empty.

To verify that the template itself was working, I then performed the following steps:

1. In Sourcetree, click the terminal button
2. Entered the following commands
   1. git add .committemplate.txt
   2. git commit

vi came up with the words "test template" filled in. However, exiting the terminal, closing and re-opening the repository or even restarting Sourcetree had no effect - Sourcetree still presents me with an empty commit message.

comments: author: KieranA
body: Hey Carl.Could you open an issue on jira.atlassian.com and link back to here? Us devs don't really come on AAC any longer due to time constraints.Cheers


author: Carl Menezes
body: Done. <https://jira.atlassian.com/browse/SRCTREEWIN-2524>. Cheers!


author: KieranA
body: Hi Paolo,

I've just tested this myself and it works fine both from within SourceTree and the command line taking me to vi. I ensured I followed the Git doc guide (rather than doing it my own way). It's better to use $HOME and have a relative link from there rather than an absolute link. So here's what I did:

1. In the terminal I typed "touch $HOME/.gitmessage.txt"
2. Then in the terminal I did "open $HOME/.gitmessage.txt" and edited the file typing in anything, in my case the first line was "Author: Kieran Senior" so I knew it was definitely using that file.
3. In the terminal I went to my repo directory and typed "git config commit.template $HOME/.gitmessage.txt" so it was only set for that repository.
4. I opened up SourceTree and using that specific repository hit commit and the commit window showed my template.
5. I then typed in 'git commit -a' as you did in the terminal which opened vi and showed me my template.

So in both instances this worked fine. There's a number of reasons this didn't work for you, the git message template not being found, or not existing, or the correct git setting not being set. Perhaps try step 3 above ensuring that it points to a valid file.

Hope that helps

comments: author: Raistlin Majere
body: No, it doesn't help, this doesn't work at all. SourceTree just doesn't honor the commit template. I'm using Windows 8 and neither a custom file name, nor a .git_template.txt file as explained here (<https://jira.atlassian.com/browse/SRCTREE-982>), nor a .gitmessage.txt. It just doesn't work, or it's broken, or never was implemented, choose the one you like at most. Don't point to "user's dumbness" when lots of people say that this doesn't work.


author: bjjenson
body: This worked just fine in OSX. Thanks!


author: Mark
body: I have the same problem where the commit template is showing up fine in a terminal session but not in Source Tree (it's blank). I've verified/tried the following:

1. The entry in the config file is showing the same in Source Tree as it is in a terminal

\[commit\]

template = $HOME/.gitcommitmessage.txt

2. I've changed the .gitcommitmessage.txt file to contain nothing but a single word, and that didn't help

3. I tried both --global and non-global when running "git config commit.template $HOME/.gitcommitmessage.txt"

4. I set the config.template to a bogus value and got an error in the terminal, but still blank in SourceTree.

It seems SourceTree isn't reading the config.template setting at all even though I see it when I click on "Edit Config File..."


Tags: git