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:
- […] all other branches from my team
Note: the prefix
protected/ is a valid prefix for branch names
The workflow is:
- everything that is in
masterwill be pushed periodically to
- as soon as changes in
protected/developmentare detected, the development site will be deployed
- every morning the latest source from
protected/developmentwill be pushed to
protected/stagingand the staging deployment site is started
- once we are happy with the state of the staging site, we decide to manually start the deployment of the production site by pushing the source from
- using the
protected/*branches directly by the team members is not allowed
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 file=sync_repos_1branch.sh]
you can call this script as following:
./sync_repos.sh [path_to_work_in] [ssh/http-origin] [ssh/http-destination] [origin-branch] [destination-branch]
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!Tweet
comments powered by Disqus