Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a Git repo one one server. i want that whenever an admin pushes changes to git repo, those changes may automatically be deployed to a folder on the same server, where git repo is hosted.

As my repo is in /opt/myrepo.git , i have created the scripts /opt/myrepo.git/hooks/post-commit .

when i perform any commit on the repo, the above script should run, but it does not. i have wrote simple Echo commands in it to test its output to a file, but it doesnt run at all.

share|improve this question

closed as off-topic by Andrew Schulman, HBruijn, Ward, mdpc, Cristian Ciupitu Jan 14 at 12:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Is the post-commit file executable (chmod +x /opt/myrepo.git/hooks/post-commit)? –  mtak Apr 23 '14 at 15:11
    
yes, obviously it is –  Farhan Apr 23 '14 at 15:12
    
@Farhan have you figured out the issue? can you please share what you did to make it work? –  JeyKeu Jun 18 '14 at 5:34
    
still not resolved :( –  Farhan Jun 18 '14 at 9:52
1  
Describing "it's broken" isn't particularly helpful. You should show exactly where each repo is, show the hook files and their permissions and demonstrate the problem. Did you already search for dupliates? This is more of an SO question than SF IMO. –  AD7six Jan 13 at 10:29

2 Answers 2

For pushes you should use the post-receive hook and not the post-commit hook.

I made the same mistake due to the odd naming convention

share|improve this answer
    
tried with post-receive as well, didnt worked –  Farhan Apr 23 '14 at 15:15
    
I know it sounds obvious but have you tried just running your script manually e.g. /opt/myrepo.git/hooks/post-commit just to check there are no typos at the start –  Phil Apr 23 '14 at 15:18
    
yes, when manually run,it works fine –  Farhan Apr 23 '14 at 15:20

Apart from using the post-hook you should make sure that the your hook file is executable. So take a look at the file permissions make sure that you have chmoded the file to a+x.

chmod a+x post-receive

post-receive hook should be executable by git. If its not executable then git doesn't inform you.

Also, make sure the first line is #!/bin/sh

Hope this helps

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.