I'm stacking all files in a single directory for all development phases
cd /home/user/website.com/
Considering my developement and testing server is my laptop, creating stag
and prod
folders 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.
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
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
Change
stag
to, for exampleprod
, and repeat all of the steps above to create an additional deployment folder for development.