1

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)

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.

jaycode
  • 2,926
  • 5
  • 35
  • 71

1 Answers1

1

Both 4a and 4b are commonly used.

I prefer 4b, as you have all the history of your repo available right in the production folder. You can see more at:

Regarding branches, start simple, and add those when needed.
But don't forget that with a distributed VCS, you can push to an intermediate repo, which can notify a job scheduler like Jenkins of a new commit, in order to run some tests.
If those tests pass, then you can push to the prod repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for your reply, and thanks for mentioning Jenkins! it looks like something I can use in this project. – jaycode Oct 27 '13 at 19:12
  • @jaycode yes, I like to promote the idea of intermediate repo (as I explain in http://stackoverflow.com/a/13653253/6309), with the possibility of guarded commits: http://stackoverflow.com/a/3209767/6309. – VonC Oct 27 '13 at 19:14