Sometimes it’s more convenient to just deploy the code to your staging server automatically when it’s being pushed to the remote repository. Although this is not recommended for Production at all, but it works well for the Staging server.
To set this up you just need to setup a hook on the remote repository for “post-receive”.
$ ssh to_remote_server $ cd /path/to/git/repository $ git config core.worktree /path/to/git/repository $ git config receive.denycurrentbranch ignore $ cat > .git/hooks/post-receive #!/bin/sh git checkout -f ^D
And finally make sure that the “post-receive” hook, has proper permissions to be executed.
chmod +x hooks/post-receive
Note: Make sure that the user is already part of the group who owns the directory which repository is located under.
Otherwise add it manually to the group.
In my case which the remote computer is a Mac, I have to execute the following command to add my username to the “wheel” group which owns the directory:
sudo dseditgroup -o edit -a my_username -t user wheel
References: This blog post helped me a lot.