Git: Using repositories/branches for source separation

Git Logo

Git is a wonderful and easy way to manage your source code of any kind of project and using GitHub as the central is a smart move. Especially when you developing a web project it is always good to have a staging site where you can see the latest stage of the development in a production-like environment.

But what if your company wants you to separate the source code into development, staging and production stages? You can use branches even completely separated repositories to achieve that.

In my current project I've set up this branching system with a single repository:

Note: the prefix protected/ is a valid prefix for branch names

The workflow is:

We are using JetBrains Teamcity to manage and execute these steps automatically. One of these steps is a shell script to synchronize the git branches.

[gist id=5344861]

you can call this script as following: ./ [path_to_work_in] [ssh/http-origin] [ssh/http-destination] [origin-branch] [destination-branch]

example: ./ ~/repos/dev protected/development protected/staging

Note: The path_to_work_in is necessary to create a bare repository as working base

Bonus: here is a script that makes a backup of you whole repository including the tags.

Have fun setting up your own branching system!

comments powered by Disqus