0

I have been trying to initialize a git repository, but I can't even make the initial commit since it fails by giving me the error below. I tried uninstalling python and installing it again, running git bash as admin, but to no avail. Also... I couldn't find anything else with this error:

$ git commit -m "init"
.git/hooks/pre-commit: line 11: py: command not found
.git/hooks/pre-commit: line 12: py: command not found
sketing
  • 9
  • 5
  • What did you do before `git commit` to create the repository? – mkrieger1 Aug 25 '22 at 12:51
  • git init, git add . , – sketing Aug 25 '22 at 12:54
  • 1
    there seems to be a `pre-commit` hook in `.git/hooks/`. If you never wanted it, you can simply remove it – leun4m Aug 25 '22 at 12:55
  • If this was the result of a simple `git init` (and without the directory being a git repository before that), you should check your `~/.gitconfig` file, to see if it adds any pre-commit hooks by default. – 9769953 Aug 25 '22 at 12:56
  • NB: assuming `py` is indeed an alias of sorts for `python`, then I'd say this is a bad pre-commit hook in the first place, because it relies on some alias a user would have to define first. – 9769953 Aug 25 '22 at 12:57
  • @9769953 It's not an alias, it's a stupid Windows launcher that allows to have a few different Python versions in registry without putting any of them in `%PATH%`. See https://stackoverflow.com/a/50896577/7976758 – phd Aug 25 '22 at 13:00
  • @phd Sounds even worse. But `.git/hooks/pre-commit` seems very unix-y, not a Windows path. It's like this repository was cloned/copied, then attempting to be used for a new project with `git init`. – 9769953 Aug 25 '22 at 13:03
  • @9769953 I'm sure it's a `git-bash` terminal. Unix-like commands and directory paths in Windows. `/c/windows` must be added to `$PATH` for `py` to work in bash. – phd Aug 25 '22 at 13:27
  • @phd Good point. I'd forgotten that exists. But overall, shouldn't there simply not be a pre-commit hook by default in the first place? And certainly not something that is so Windows specific. – 9769953 Aug 25 '22 at 13:45
  • @9769953 "*shouldn't there simply not be a pre-commit hook by default in the first place?*" Perhaps the OP did `git config --global core.hooksPath hooks` some time ago and forgot about the global hooks. Now they bit. – phd Aug 25 '22 at 13:58
  • Oh... another thing I did. I installed git LFS – sketing Aug 25 '22 at 14:00
  • But did you check your git (global) configuration? – 9769953 Aug 25 '22 at 14:04
  • 1
    actually, I just ran `git config --global core.hooksPath hooks` by accident :D – sketing Aug 25 '22 at 14:09
  • and I updated git, which seems to have fixed the issue – sketing Aug 25 '22 at 14:09

0 Answers0