I have a local repository, and I have set up another repository on my live server:
www.site.com/projects/ProjectA
What I want to achieve is very simple: After I PUSH to GitHub, I want the repository at www.site.com/projects/ProjectA to PULL - hence update the live version of the project, that my client can see.
I've been reading tons about hooks and I cannot find a very simple example for what I need. All tutorials are made for advanced functionality.
What I have done
I have a remote repository at www.site.com/projects/ProjectA that I created while logged in with Putty and doing git clone (at this point my local repo, the GitHub repo and the server repo were all in sync)
I copied post-receive.sample from .git/hooks to www.site.com/projects/ProjectA/
I made a local change, commit, push. The Hub updates, the hook shows a new recent delivery. All is well, but the server repository does not update.
The "hook" code is ". /usr/share/git-core/contrib/hooks/post-receive-email" and I don't understand what that does. I looked at other hook samples and I saw some of them have familiar commands like: exec git update-server-info so I figured I could write my own command. so I wrote git pull, saved it and did the change - commit - push again from my local repo. The result was the same as before. I then tried exec git pull. Same thing.
My question is - what am I doing wrong, and the second question is, why the heck isn't there a simple tutorial for this functionality, since this seems to be one of the most usual scenarios. Thank you!
Just saw this unanswered even after years.
Webhooks require you to setup a HTTP POST listener on your server. You can add a http route in your project and perform appropriate pull action.
Reference: Webhooks
There is an alternate implementation which I use in my projects:
Suppose ~/example is your project public/www folder. Ssh into your server:
$ cd ~/example && mkdir .git && cd .git && git init --bare
$ cat > hooks/post-receive << EOF
> #!/bin/sh
> GIT_WORK_TREE=~/example git checkout -f
> EOF
$ chmod +x hooks/post-receive
The above will create a bare git repo in ~/example/.git
folder. Add a post-receive executable hook and perform checkout into the example directory.
On local repo:
$ git remote add server ssh://my_user@my_server.com:/absolute_path/example/.git/
$ git push server +master:refs/heads/master
This works well for me. I can push, revert commits whenever I need.
Reference: Server repository
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With