This Git warning appears when a pre-commit hook file exists but lacks executable permissions. Git detects the hook but cannot run it. The fix is to make the hook file executable with chmod.
When you commit changes in Git, it checks for hook scripts in the `.git/hooks/` directory (or a custom hooks path). These hooks allow you to run custom scripts at various points in the Git workflow, such as before a commit is finalized. Git detected a `pre-commit` hook file in your hooks directory, but the file doesn't have the executable permission bit set. On Unix-like systems (Linux, macOS), files need to be marked as executable to be run as scripts. Without this permission, Git cannot execute the hook and displays this warning instead. This commonly occurs when: - Hook files are copied or created manually without setting permissions - Files are cloned from a Windows machine where executable bits are not preserved - You're using Husky or another hook manager that didn't set permissions correctly - The file was added to Git on Windows and checked out on Linux/macOS
The most direct fix is to add the executable permission to the hook file:
chmod +x .git/hooks/pre-commitIf you're using Husky (hooks in .husky/ directory):
chmod +x .husky/pre-commitTo make all hooks executable at once:
chmod +x .git/hooks/*
chmod +x .husky/*Check that the permission was set correctly:
ls -la .git/hooks/pre-commitYou should see -rwxr-xr-x or similar (the x indicates executable). The output should look like:
-rwxr-xr-x 1 user user 478 Jan 15 10:30 .git/hooks/pre-commitNow try a commit to confirm the hook runs:
git commit --allow-empty -m "Test hook"If you manually created the hook file, it won't have executable permissions. Remove it and use Husky's command:
rm .husky/pre-commit
npx husky add .husky/pre-commit "npm test"Or with Yarn:
yarn husky add .husky/pre-commit "yarn test"This creates the file with correct permissions (755).
Add chmod to your prepare script to ensure permissions are set after install:
{
"scripts": {
"prepare": "husky install && chmod ug+x .husky/*"
}
}This runs automatically when team members run npm install or yarn install, fixing permissions on all machines.
If you have a custom hooks path configured, ensure it points to the correct location:
git config --get core.hooksPathIf this returns an unexpected path, you can reset it:
git config --unset core.hooksPathOr set it to your hooks directory:
git config core.hooksPath .husky### Windows to Linux/macOS Migration
When hooks are created on Windows and pushed to a repository, the executable bit isn't preserved because Windows doesn't have the same permission model. When these are cloned on Unix systems, they won't be executable.
Solution for teams: Add a post-checkout or prepare script that sets permissions:
# In package.json
"postinstall": "chmod +x .husky/* 2>/dev/null || true"### File System Limitations
If you're working on an NTFS partition mounted in Linux (common with dual-boot setups), the mount options may not support executable permissions. Check your /etc/fstab or mount options:
mount | grep ntfsYou may need to remount with exec option or work from a native Linux filesystem.
### Disabling the Warning (Not Recommended)
You can suppress the warning without fixing it:
git config advice.ignoredHook falseWarning: This only hides the message. Your hooks still won't run, defeating their purpose.
### pre-commit Framework Users
If you use the pre-commit Python framework instead of Husky:
pre-commit install --install-hooksThis properly installs hooks with correct permissions. If hooks still fail:
pre-commit clean
pre-commit install### Git Executable Bit Tracking
Git can track the executable bit. To preserve permissions across clones:
git update-index --chmod=+x .husky/pre-commit
git commit -m "Make pre-commit hook executable"This ensures the file is executable for everyone who clones the repository.
warning: BOM detected in file, this may cause issues
UTF-8 Byte Order Mark (BOM) detected in file
fatal: Server does not support --shallow-exclude
Server does not support --shallow-exclude
warning: filtering out blobs larger than limit
Git partial clone filtering large blobs warning
fatal: Server does not support --shallow-since
Server does not support --shallow-since in Git
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server