Take the 2-minute tour ×

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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

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

share|improve this answer
I'm running git v1.7.6 on Mac OS X Lion. I'd done git init to reinitialize the repo and that still didn't work. I edited the file in TextMate, which might be the problem, but still doesn't explain why git init wouldn't do the chmod u+x properly. –  Josh Smith Dec 22 '11 at 2:07
@JoshSmith git init only creates sample hooks, not actual ones. I'm running on Lion, and 1.7.0 on Ubuntu--they both create the sample files as u+x--I guess I'm a little skeptical it isn't on yours. –  Dave Newton Dec 22 '11 at 2:10
If nothing else I discovered my Linux box is running an old-ish version of git. –  Dave Newton Dec 22 '11 at 2:11
So am I going to have to chmod every single time I modify the hook? –  Josh Smith Dec 22 '11 at 2:12
@JoshSmith Uh, no, once it's set, you shouldn't need to change it again. –  Dave Newton Dec 22 '11 at 2:13
show 2 more comments

Your Answer


