1

Git is reading a stale template path. This path used to be in my older VM. I had copied this git directory as it is to a new VM. I tried removing "[commit] template" entry from ~/.gitconfig, followed by git commit but it still gives me this error. Then I tried removing all entries but to no avail.

$ git config --global --unset-all commit.template
$ git commit
fatal: could not read '/home/subtleseeker/main/commit-template.txt': No such file or directory

Any idea, where git is reading this path from?

$ git config --global commit.template /home/peeches/main/commit-template.txt
$ git config -l | grep template
commit.template=/home/peeches/main/commit-template.txt
commit.template=/home/subtleseeker/main/commit-template.txt
$ git config --global --unset-all commit.template
$ git config -l | grep template
commit.template=/home/subtleseeker/main/commit-template.txt

Git version: git version 2.30.1 OS: CentOS Linux release 7.9.2009 (Core)

subtleseeker
  • 4,415
  • 5
  • 29
  • 41

1 Answers1

2

The config is local

commit.template=/home/peeches/main/commit-template.txt
commit.template=/home/subtleseeker/main/commit-template.txt

This shows two entries, git checks/outputs config in the following order:

When reading, the values are read from the system, global and repository local configuration files by default

Based on the order of the output in the question, the unwanted config entry is from the local repository's git config.

Therefore, to remove that reference, delete from local config:

$ git config --unset commit.template

Note: The --local flag can be specified to be explicit - but that's the default behavior for write operations (see the docs for more info) so not necessary.

That's almost certainly the case in the question though there are actually more places git checks for config:

  • $(prefix)/etc/gitconfig
  • $HOME/.config/git/config
  • ~/.gitconfig
  • $GIT_DIR/config
  • $GIT_DIR/config.worktree (only if extensions.worktreeConfig is enabled)

If in doubt, check each in turn.

Reproduction

Consider:

$ git init
Initialized empty Git repository in /tmp/so/.git/
➜  so git:(master) git config some.thing=local
error: invalid key: some.thing=local
➜  so git:(master) git config some.thing local
➜  so git:(master) git config --global some.thing global
➜  so git:(master) git config -l | grep some.thing
some.thing=global
some.thing=local
➜  so git:(master)

This simulates the situation in the question. Removing global config, does not affect the local config:

➜  so git:(master) git config --global --unset-all some.thing
➜  so git:(master) git config -l | grep some.thing
some.thing=local
➜  so git:(master)

But updating the local config does:

➜  so git:(master) git config --unset some.thing
➜  so git:(master) git config -l | grep some.thing
➜  so git:(master)
AD7six
  • 63,116
  • 12
  • 91
  • 123