Skip to content

error: Command get git root exited with an error: #1239

@jmelahman

Description

@jmelahman

Summary

I recently migrated my dotfiles to https://www.atlassian.com/git/tutorials/dotfiles which uses a non-default value for --git-dir.

I also have a global ~/.githooks w/ post-merge/post-checkout, etc. hooks.

Because the GIT_DIR is unset in the hook config, all of the subsequent git commands fail (fair enough),

$ git --git-dir=$HOME/.dotfiles --worktree=$HOME checkout --
error: Command `get git root` exited with an error:

[status]
exit status: 128

[stderr]
fatal: not a git repository (or any of the parent directories): .git

Maybe naively, it seems feasible to instead save the GIT_DIR and pass it to prek and use it internally when applicable at least to initialize the hook running.

Repro steps:

git clone --bare git@github.com:j178/prek.git /tmp/prek-bare
mkdir /tmp/prek
cd /tmp/prek
git --git-dir=/tmp/prek-bare --work-tree=/tmp/prek checkout --

Platform

Linux 6.17.9-arch1-1 x86_64 GNU/Linux

Version

0.2.22

.pre-commit-config.yaml

None/Not relevant

Log file

$ cat ~/.cache/prek/prek.log
2025-12-19T08:53:12.489024Z DEBUG prek: 0.2.22
2025-12-19T08:53:12.489048Z DEBUG Args: ["/usr/bin/prek", "hook-impl", "--hook-type=post-merge", "--color=always", "--skip-on-missing-config", "--script-version=3", "--hook-dir", "/home/jamison/.githooks", "--", "0"]
2025-12-19T08:53:12.490315Z TRACE get_root: close time.busy=1.24ms time.idle=2.20µs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions