How should I organize my Git repositories and branches to create multiple versions of a website?

3.3k views Asked by At

I'm an SVN user hoping to move to Git. I've been reading documentation and tutorials all day, and I still have unanswered questions. I don't know if this workflow will make sense, but here's my situation, and what I would like to get out of my workflow:

  • Multiple developers, all developing locally on their work stations
  • 3 versions of the website: Dev, Staging, Production

Here's my dream:

A developer works locally on his own branch, say "developer1", tests on his local machine, and commits his changes.

Another developer can pull down those changes into his own branch. Merge developer1 -> developer2.

When the work is ready to be seen by the public, I'd like to be able to "push" to Dev, Staging, or Production.

git push origin staging 

or maybe

git merge developer1 staging

I'm not sure. Like I said, I'm still new to Git.

Here are my main questions:

  • Do my websites (Dev, Staging, Production) have to be repositories? And do they have to be "bare" in order to be the recipients of new changes?

  • Do I want one repository or many, with several branches?

  • Does this even make sense, or am I on the wrong path?

I've read a lot of tutorials, so I'm really hoping someone can just help me out with my specific situation. Thanks so much!

3

There are 3 answers

3
Greg Hewgill On

An article I recommend reading is A Successful Git Branching Model. It addresses the situations you describe plus some more.

0
ulidtko On

Remember about the distributedness. Unlike in subversion, your developers' checkouts are their own independent repositories, not just working copies. In their normal workflow they would commit their changes to own repository, create and manipulate personal branches, etc. The git push can be used to transfer commits from local branches to your "main", origin repository (which will probably reside at webhosting). Therefore, each developer would have local personal repo with whatever set of branches he wishes; origin repository would have the three mentioned branches. Developers from time to time would git pull others work from origin repo (into some local branch) and git push their own work to appropriate branches of origin repo.

0
ServAce85 On

As @Greg suggested, following the Successful Git Branching Model by nvie is a great idea. From there, I would suggest reading about how to use git for websites and try to implement that with the branching model in mind.

In short:

  • Follow the git branching model to a T
  • Set up your system to allow git to push your release branches to your staging server in the manner suggested by the second article
  • Set git up to push your master branch to your production server following the same staging server setup