Skip to content

Instantly share code, notes, and snippets.

@5eleven
Created July 18, 2012 08:03
Show Gist options
  • Save 5eleven/3134939 to your computer and use it in GitHub Desktop.
Save 5eleven/3134939 to your computer and use it in GitHub Desktop.
Git Deployment
//First, create a directory on your server and initialize an empty git repository. I like to serve my websites from ~/www/, so that's what I'll do in this example.
mkdir ~/www/example.com && cd ~/www/example.com
git init
//Next, let's set up your server's git repo to nicely handle deployment via git push.
git config core.worktree ~/www/example.com
git config receive.denycurrentbranch ignore
//Finally, we'll set up a post-receive hook for git to check out the master branch so your web server can serve files from that branch. (Remember, ^D is Control+D, or whatever your shell's EOT character is.
cat > .git/hooks/post-receive
#!/bin/sh
git checkout -f
^D
chmod +x .git/hooks/post-receive
//Back on your local machine, let's get your git repo ready for deployment.
cd ~/www-dev/example.com
git remote add origin \
ssh://user@example.com/home/user/www/example.com
//Now, whenever you want to deploy changes you've made locally, simply run the following command!
git push
// Credit: http://coderwall.com/p/xczkaq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment