diff --git a/pre_commit/commands/init_templatedir.py b/pre_commit/commands/init_templatedir.py
index c1b9562..6e8df18 100644
--- a/pre_commit/commands/init_templatedir.py
+++ b/pre_commit/commands/init_templatedir.py
@@ -2,6 +2,7 @@ import logging
 import os.path
 
 from pre_commit.commands.install_uninstall import install
+from pre_commit.util import CalledProcessError
 from pre_commit.util import cmd_output
 
 logger = logging.getLogger('pre_commit')
@@ -12,9 +13,14 @@ def init_templatedir(config_file, store, directory, hook_type):
         config_file, store, overwrite=True, hook_type=hook_type,
         skip_on_missing_config=True, git_dir=directory,
     )
-    _, out, _ = cmd_output('git', 'config', 'init.templateDir', retcode=None)
+    try:
+        _, out, _ = cmd_output('git', 'config', 'init.templateDir')
+    except CalledProcessError:
+        configured_path = None
+    else:
+        configured_path = os.path.realpath(os.path.expanduser(out.strip()))
     dest = os.path.realpath(directory)
-    if os.path.realpath(out.strip()) != dest:
+    if configured_path != dest:
         logger.warning('`init.templateDir` not set to the target directory')
         logger.warning(
             'maybe `git config --global init.templateDir {}`?'.format(dest),
diff --git a/pre_commit/main.py b/pre_commit/main.py
index 53c2dba..dbfbecf 100644
--- a/pre_commit/main.py
+++ b/pre_commit/main.py
@@ -36,6 +36,9 @@ logger = logging.getLogger('pre_commit')
 os.environ.pop('__PYVENV_LAUNCHER__', None)
 
 
+COMMANDS_NO_GIT = {'clean', 'gc', 'init-templatedir', 'sample-config'}
+
+
 def _add_color_option(parser):
     parser.add_argument(
         '--color', default=os.environ.get('PRE_COMMIT_COLOR', 'auto'),
@@ -273,7 +276,7 @@ def main(argv=None):
         parser.parse_args(['--help'])
 
     with error_handler(), logging_handler(args.color):
-        if args.command not in {'clean', 'gc', 'sample-config'}:
+        if args.command not in COMMANDS_NO_GIT:
             _adjust_args_and_chdir(args)
 
         git.check_for_cygwin_mismatch()

`pre-commit init-templatedir` should expanduser before checking value to warn on
https://github.com/pre-commit/pre-commit/issues/1084#issuecomment-513744333
diff --git a/tests/commands/init_templatedir_test.py b/tests/commands/init_templatedir_test.py
index 2910ac9..b94de99 100644
--- a/tests/commands/init_templatedir_test.py
+++ b/tests/commands/init_templatedir_test.py
@@ -1,5 +1,8 @@
+import os.path
 import subprocess
 
+import mock
+
 import pre_commit.constants as C
 from pre_commit.commands.init_templatedir import init_templatedir
 from pre_commit.envcontext import envcontext
@@ -47,3 +50,32 @@ def test_init_templatedir_already_set(tmpdir, tempdir_factory, store, cap_out):
     lines = cap_out.get().splitlines()
     assert len(lines) == 1
     assert lines[0].startswith('pre-commit installed at')
+
+
+def test_init_templatedir_not_set(tmpdir, store, cap_out):
+    # set HOME to ignore the current `.gitconfig`
+    with envcontext([('HOME', str(tmpdir))]):
+        with tmpdir.join('tmpl').ensure_dir().as_cwd():
+            # we have not set init.templateDir so this should produce a warning
+            init_templatedir(C.CONFIG_FILE, store, '.', hook_type='pre-commit')
+
+    lines = cap_out.get().splitlines()
+    assert len(lines) == 3
+    assert lines[1] == (
+        '[WARNING] `init.templateDir` not set to the target directory'
+    )
+
+
+def test_init_templatedir_expanduser(tmpdir, tempdir_factory, store, cap_out):
+    target = str(tmpdir.join('tmpl'))
+    tmp_git_dir = git_dir(tempdir_factory)
+    with cwd(tmp_git_dir):
+        cmd_output('git', 'config', 'init.templateDir', '~/templatedir')
+        with mock.patch.object(os.path, 'expanduser', return_value=target):
+            init_templatedir(
+                C.CONFIG_FILE, store, target, hook_type='pre-commit',
+            )
+
+    lines = cap_out.get().splitlines()
+    assert len(lines) == 1
+    assert lines[0].startswith('pre-commit installed at')

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio
apt-get update apt-get install -y gcc
3.9
requirements-dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
aspy.yaml==1.3.0
cfgv==3.4.0
coverage==7.8.0
distlib==0.3.9
exceptiongroup==1.2.2
execnet==2.1.1
filelock==3.18.0
flake8==7.2.0
identify==2.6.9
importlib_metadata==8.6.1
iniconfig==2.1.0
mccabe==0.7.0
mock==5.2.0
nodeenv==1.9.1
packaging==24.2
platformdirs==4.3.7
pluggy==1.5.0
-e git+https://github.com/pre-commit/pre-commit.git@7f1e9c1907cd81b4a884000604e9eb6cc20c38d8#egg=pre_commit
pycodestyle==2.13.0
pyflakes==3.3.1
pytest==8.3.5
pytest-asyncio==0.26.0
pytest-cov==6.0.0
pytest-env==1.1.5
pytest-mock==3.14.0
pytest-xdist==3.6.1
PyYAML==6.0.2
six==1.17.0
toml==0.10.2
tomli==2.2.1
typing_extensions==4.13.0
virtualenv==20.29.3
zipp==3.21.0

name: pre-commit
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - aspy-yaml==1.3.0
      - cfgv==3.4.0
      - coverage==7.8.0
      - distlib==0.3.9
      - exceptiongroup==1.2.2
      - execnet==2.1.1
      - filelock==3.18.0
      - flake8==7.2.0
      - identify==2.6.9
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - mccabe==0.7.0
      - mock==5.2.0
      - nodeenv==1.9.1
      - packaging==24.2
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pycodestyle==2.13.0
      - pyflakes==3.3.1
      - pytest==8.3.5
      - pytest-asyncio==0.26.0
      - pytest-cov==6.0.0
      - pytest-env==1.1.5
      - pytest-mock==3.14.0
      - pytest-xdist==3.6.1
      - pyyaml==6.0.2
      - six==1.17.0
      - toml==0.10.2
      - tomli==2.2.1
      - typing-extensions==4.13.0
      - virtualenv==20.29.3
      - zipp==3.21.0
prefix: /opt/conda/envs/pre-commit

tests/commands/init_templatedir_test.py::test_init_templatedir_not_set tests/commands/init_templatedir_test.py::test_init_templatedir_expanduser
tests/commands/init_templatedir_test.py::test_init_templatedir tests/commands/init_templatedir_test.py::test_init_templatedir_already_set
pre_commit/main.py pre_commit/commands/init_templatedir.py
pre_commit/main.py pre_commit/commands/init_templatedir.py