Interview Prep/Git & GitHub/Submodules, LFS and Hooks

A hook fails with `/usr/bin/env: 'bash\r': No such file or directory`.

IntermediateTroubleshootingSubmodules, LFS and Hooks
Answer

Likely causes → The hook script has Windows CRLF line endings, so the shebang interpreter becomes bash\r. Usually caused by core.autocrlf=true on Windows checking out scripts with CRLF and then a Linux/WSL/container shell running them.

Diagnose →

file .githooks/pre-commit          # "with CRLF line terminators"
git ls-files --eol .githooks/

Fix → Force LF for scripts and renormalize:

printf '*.sh text eol=lf\n.githooks/* text eol=lf\n' >> .gitattributes
git add --renormalize .
git commit -m "Force LF for scripts"

Locally fix the file with dos2unix .githooks/pre-commit.

Prevent → Commit a .gitattributes with eol=lf for all shell scripts from day one.

All Git & GitHub questions Roadmap: Git & GitHub

More on Submodules, LFS and Hooks