9

I have placed a file inside .git/hooks named pre-push.sh

I am not making any check, just want to echo some error while pushing to the remote. Below is the .sh file content

protected_branch='test' echo $protected_branch exit 1 

However it is still allowing to push changes without throwing any error. Need help to find where am i making mistake?

3 Answers 3

18

The name of the hook must be exactly pre-push (not pre-push.sh, not pre-push.exe, not pre-push.py ...)

Also: the hook should be executable, otherwise it will be ignored

chmod u+x .git/hooks/pre-push 
Sign up to request clarification or add additional context in comments.

Comments

7

I just ran into the same problem and had a proper name for the hook BUT also had to make sure it was executable

chmod 766 .git/hooks/pre-push 

fixed it.

Comments

2

pre-push.sh isn't a valid hook name. Instead this needs to be placed on the server as a pre-receive hook.

5 Comments

Here is the no. of sample files for pre-push github.com/raven/git-prepush-recipes and as per documentation it works on client-side before push
OK - never used one. Always run things server side. Try without the .sh extension.
@Flash that github link is broken.
Answer is only partially correct. pre-push is a valid hook: git-scm.com/book/en/v2/Customizing-Git-Git-Hooks under "Other Client Hooks"
Downvoted for being wrong.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.