git Push & Automatic deployment

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s