Why is my Git pre-commit hook not executable by default?

Josh Smith picture Josh Smith · Dec 22, 2011 · Viewed 26.1k times · Source

If you see the accepted answer in: Aggregating and uglifying javascript in a git pre-commit hook, you'll see that I had to do a chmod +x on my pre-commit hook to get it to work.

Why is this not executable by Git by default?

Answer

Dave Newton picture Dave Newton · Dec 22, 2011

Because files are not executable by default; they must be set to be executable.

The sample files from a git init are all executable; if it's copied or renamed to a non-sample file, it will retain the original file's x flag.

New files will be created with current defaults. In your case, view those defaults with umask:

$ umask
0022

By default, new files won't be u+x unless explicitly set to be.