Created
June 27, 2013 03:30
-
-
Save onel0p3z/5873734 to your computer and use it in GitHub Desktop.
FTP is so 90's. Let's deploy via Git instead! from https://coderwall.com/p/xczkaq?&p=1&q=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Keep in mind that you can add whatever you like to the post-receive hook if you have a build process. For example, one of my sinatra projects uses the following post-receive hook: | |
#!/bin/sh | |
git checkout -f | |
bundle install | |
touch ~/www/example.com/tmp/restart.txt | |
Back on your local machine, let's get your git repo ready for deployment. | |
cd ~/www-dev/example.com | |
git remote add origin \ | |
ssh://[email protected]/home/user/www/example.com | |
For the first push to your server, run the following command. | |
git push origin master | |
Now, whenever you want to deploy changes you've made locally, simply run the following command! | |
git push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment