First of all thank you for your time reading this question.
I am currently researching on which Git workflow is most suitable for website development in the company I work for. There are different guides all over the net, but they mostly are conceptual. Please let me know if my way of implementing it is wrong:
1. The Concept
Conceptually there would be 4 tiers, development, integration, staging, and production. development tier is stored locally, integration is done with Git's help, production tier is located directly at public_html, and staging tier to preview the site before release is available at a protected directory __dev/staging (or better yet, __dev/[branch_name] ?).
2. Folder structure (staging & production tiers)
- git
- project.git (this is the bare repository of this website project)
- public_html
- __dev (password-protected directory)
- staging (this is like a copy of public_html used as staging tier)
- __dev (password-protected directory)
3. Git setup within my local copy (development & integration tiers)
git remote add origin ssh://path_to_project.git
git branch staging
That way I got two branches to start, master and staging.
When I do
git push origin master
The online version of the site should be updated without me having to ssh connect to the site. And when I do
git push origin [branchname]
__dev/[branchname] should be updated automatically.
All the above could be done via git hooks. The reason of this automation instead of ssh connect and pull is this allow for faster development (otherwise if it takes more effort than ftp, what for :/. Do you agree?)
4. Hook
This is where I got rather confused.
What I had in mind was either one of these two flavors:
a. clone and copy
When I push to the site, the hook will clone bare repo to a temporary directory and copy it to public_html or __dev/branch depending on which branch I sent over.
b. reset and pull
When I push to the site, the hook will check if there is already a .git directory inside public_html or __dev/branch
If none found, cd to that directory and git init, then git pull.
If found, cd to that directory and git reset --head then git pull
App installation using installatron or softaculous
Sometimes I like to install the web app from installatron, and use that as a working base. Unfortunately there is no hook to automatically push to git after the installation done, so I have to connect to ssh and do:
git add .
git commit -a -m "installed xxx app"
git push origin master
Then pull it in my local repository.
Conclusion and Question
What do you think about the workflow I had in mind? Is there anywhere I need to improve? Is the arrangement of branches okay? Which flavor is better 4.a. or 4.b., or is there another?
Thank you.