Skip to content

Instantly share code, notes, and snippets.

@patarkf
Last active August 29, 2015 14:15
Show Gist options
  • Save patarkf/43c95f7427ed2b56b1dd to your computer and use it in GitHub Desktop.
Save patarkf/43c95f7427ed2b56b1dd to your computer and use it in GitHub Desktop.
GIT to deploy website
Hey, folks. Below, the steps that I followed (after a little search on the web) to deploy my application
(website) using GIT, on the cleanest and easiest way. The advantage of this method is that any small
change pushed to remote repo will be published in your live website.
Step 1: Create the local GIT repository
$ cd /var/www/project/
$ git init
$ git add *
$ git commit -am "first commit"
Step 2: Prepare the server (if you already have the SSH key)
$ ssh user@domain.com
$ mkdir -p ~/project.git && cd $_
$ git init --bare
Step 3: Create a post-receive hook on server and create an empty folder for the project
First, we'll create a empty folder to our project
$ mkdir /var/www/domain.com/project
After that, we'll create the hook:
$ cat > hooks/post-receive << EOF
#!/bin/sh
echo 'This line will help you to see that this hook is working'
GIT_WORK_TREE=/var/www/domain.com/project git checkout -f
EOF
And finally, give it permission to write:
$ chmod -x hooks/post-receive
Step 4: In your local project directory, add your remote repo
$ git remote add server user@domain.com:/home/project.git ("server" will be the name of remote)
$ git push server +master:refs/heads/master
Step 5: Test and be happy!
----------------------------------------------------------------------------------------------------------------------------------
After the first commit, the normal flow would be:
[change local file]
git commit -am "Always comment your commits, pls"
git push server
And that's it, folks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment