1

I develop on my Mac and push it to Github. I login to my server by SSH and I git pull the changes to the server. I want the changes to automatically be pulled to the server when I push them to Github so I a file .git/hooks/post-update with this info

#!/bin/sh echo echo "**** Pulling changes into Live [Hub's post-update hook]" echo cd /mydirector/html || exit unset GIT_DIR git pull exec git-update-server-info 

What else should I do to get it working? Thanks in advance for your answer. It will be very much appreciated.

1
  • You could also just push to github AND the server Commented Sep 12, 2014 at 18:54

2 Answers 2

0

You could also declare a webhook on GitHub, in order to generate an event payload that can be listened to by a process on your server.

That process (a listener) would be in charge of triggering the git pull.

You will find various examples of such listeners, like:

Sign up to request clarification or add additional context in comments.

Comments

0

You need to realize that the hook can not work ok the server for this use case. The server has no way to know you did a push (unless you have a github webhook setup and working, in which case, look at answer by @VonC), so the hook for the update would need to be local. Hooks are really not intended for this purpose as stated here: Local executing hook after a git push?

What you really want to do is push your changes to both the github, and your server. The easiest way would just be to push to both. See pull/push from multiple remote locations

Usually git-hooks are added to the server so that after you push to the server, the server can do some extra stuff (like start the app or something). (Here is a good article: http://danbarber.me/using-git-for-deployment/)


However, as you requested, you could alternatively use the post-receive script to simply do the push. Since git does not support post-push git hooks, this would have to run on the git repository. Github however, does not allow these (they only allow webhooks, for security reasons of course). But if it did, you could do:

#!/bin/sh git remote add live [email protected]:www/mysite git push live master exec git update-server-info 

And make sure to set the file as executable chmod a+x post-receive

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.