Skip to content

Instantly share code, notes, and snippets.

@refo
Last active January 9, 2018 12:22
Show Gist options
  • Save refo/60128cee9835ed407b6a to your computer and use it in GitHub Desktop.
Save refo/60128cee9835ed407b6a to your computer and use it in GitHub Desktop.
Deploy website using git checkout

Deploy website using git checkout

Remote Shell

Create a base directory

I'm stacking all files in a single directory for all development phases

cd /home/user/website.com/

Create deployment directories

Considering my developement and testing server is my laptop, creating stag and prodfolders for Staging and Production phases respectively.

mkdir -p stag/{git,live}
mkdir -p prod/{git,live}
...

git subfolder will be created as a bare repository to push changes from local and live folder will be the folder where website served.

Prepare remote repository

Assuming i'm still at the base directory (home/user/website.com/) at this point.

Initialize repo directory

cd stag/git
git init --bare

Edit/create hooks/post-receive hook file and put the following:

#!/bin/sh
GIT_WORK_TREE=../live git checkout -f

Make the hook executable

chmod +x hooks/post-receive

Local Shell

chdir /to/local/repository
git remote add stag ssh://user@website.com/home/user/website.com/stag/git
git push stag +master:refs/heads/master

At this point, /home/user/website.com/stag/live directory on remote server should contain a copy of repository files freed from git meta files.

After this point, anytime i want to push a change to remote server, all i need to do is;

git push stag

Conclusion

Change stag to, for example prod, and repeat all of the steps above to create an additional deployment folder for development.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment