Mini tutorial for /u/smug_rum_smuggler and /u/itmcb.
Beware, I haven't tested this. Let's assume a few things:
- your project is called "myproject"
- your server is at "myserver.com"
- you have SSH access to the server with the user "bob"
- your project on the server is at
/home/bob/myproject
- the "master" branch is the stable branch
Set up a directory where you put all your git repos:
mkdir ~/gitrepos
Create a bare Git repository as the source for your code directory where you put all your git repos:
cd ~/gitrepos
git init --bare myproject.git
Go to your project directory and initialize a new repo (unless it's already a checkout) and add the bare repo as a remote called "source":
cd ~/myproject
git init
git remote add source /home/bob/gitrepos/myproject.git
Set up the post-receive hook. Edit the file ~/gitrepos/myproject.git/hooks/post-receive
and add the following:
#!/bin/sh
cd /home/myproject
env -e git pull --rebase source master
# add more commands below, like e.g. `npm install` if node project
Make the file executable:
chmod +x ~/gitrepos/myproject.git/hooks/post-receive
Go to your local repo and add a remote called "deploy":
cd path/to/my/repo/
git remote add deploy ssh://[email protected]:/home/bob/gitrepos/myproject.git
Make some changes in the master branch and commit:
git checkout master
echo hello > testfile
git add testfile
git commit -m ohlala
Push the master branch to the remote repo:
git push deploy master
Verify that your project has the updated code:
ls -l ~/myproject
# should have the updated code