Created
May 5, 2014 23:28
-
-
Save joshuaadrian/9a4bbf01e82dfef68470 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Web server setup... SSH Keys... You can use ssh keys to log into the server without a password. I assume you have already generated your keys. | |
Open you public key at ~/id_rsa.pub, and copy it. | |
On the server, add your key to ~/.ssh/authorized_keys. | |
# On the web server, initialize an empty Git repository. First SSH into the server, then go to the website’s root directory, and run: | |
$ git init | |
# Suppress git receive error... Add this to the server’s .git/config file to suppress an error when it receives a push: | |
[receive] | |
denycurrentbranch = warn | |
# Add post-receive hook... Here’s where the magic is. Git hooks are little scripts that run after an event. Set up a post-receive hook to run a script that checks out the files the server just received. Open or create .git/hooks/post-receive and add this: | |
#!/bin/sh | |
GIT_WORK_TREE=/path/to/html/ git checkout -f | |
# Media Temple Example: | |
#!/bin/sh | |
GIT_WORK_TREE=$PWD/../ git checkout -f | |
# The post-receive file must also have correct permissions to be able to execute. Check the permissions and change the permissions if needed, like so: | |
chmod +x post-receive | |
# Check out a branch... Create and checkout the appropriate branch that corresponds to your local branch. If this is the dev server: | |
$ git checkout -b dev | |
$ git checkout -b master | |
# Now back to your local machine... Set up git remotes & Add the web server repositories as git remotes: | |
$ git remote add dev [email protected]:/.../html/ | |
$ git remote add prod [email protected]:/.../html/ | |
# Deploying... At last! You can now use git push to deploy, like so: | |
$ git push dev | |
$ git push prod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment