Git branch strategy for small dev team

ID : 20435

viewed : 4

Tags : gitbranchgit-branchgit

Top 5 Answer for Git branch strategy for small dev team

vote vote


You might benefit from the workflow Scott Chacon describes in Pro Git. In this workflow, you have two branches that always exist, master and develop.

master represents the most stable version of your project and you only ever deploy to production from this branch.

develop contains changes that are in progress and may not necessarily be ready for production.

From the develop branch, you create topic branches to work on individual features and fixes. Once your feature/fix is ready to go, you merge it into develop, at which point you can test how it interacts with other topic branches that your coworkers have merged in. Once develop is in a stable state, merge it into master. It should always be safe to deploy to production from master.

Scott describes these long-running branches as "silos" of code, where code in a less stable branch will eventually "graduate" to one considered more stable after testing and general approval by your team.

Step by step, your workflow under this model might look like this:

  1. You need to fix a bug.
  2. Create a branch called myfix that is based on the develop branch.
  3. Work on the bug in this topic branch until it is fixed.
  4. Merge myfix into develop. Run tests.
  5. You discover your fix conflicts with another topic branch hisfix that your coworker merged into develop while you were working on your fix.
  6. Make more changes in the myfix branch to deal with these conflicts.
  7. Merge myfix into develop and run tests again.
  8. Everything works fine. Merge develop into master.
  9. Deploy to production from master any time, because you know it's stable.

For more details on this workflow, check out the Branching Workflows chapter in Pro Git.

vote vote


After coming in as a novice trying to find a straight-forward strategy to teach to other devs who have never used source control. This is the one that fit I tried using the standard GIT workflow thats in the man pages but it confused me slightly and my audience completely.

Over the past 6 months I have only had to fix conflicts twice. I have added steps to always test after a merge and to 'fetch and merge" or 'pull --rebase" a lot (once in the morning and in the afternoon) while developing features. We also used as the central place to pull the latest code.

vote vote


(Made my comment above it's own answer, as I should have initially.)

From Scott Chacon of Github:

How We Do It So, what is GitHub Flow?

  • Anything in the master branch is deployable
  • To work on something new, create a descriptively named branch off of master (ie: new-oauth2-scopes)
  • Commit to that branch locally and regularly push your work to the same named branch on the server
  • When you need feedback or help, or you think the branch is ready for merging, open a pull request
  • After someone else has reviewed and signed off on the feature, you can merge it into master
  • Once it is merged and pushed to ‘master’, you can and should deploy immediately

See the entire article for more details:

Note that "pull requests" are a Github invention, and it's something that's baked into their website, not Git itself:

vote vote


Use the master branch as your development branch and create release branches for performing bug fixes.

Any new features will go on master during the development window (either committed directly or as topic branches with pull-requests, up to you -- not shown in graphic). Once all your planned features are implemented, enter feature freeze, and perform testing. When you're happy, tag the release on master as v1.0.

Over time your users will find bugs in v1.0 so you'll want to create a branch from that tag (e.g. name it after the release 1.0) and fix those bugs in the branch. When you've got enough bugs fixed that you think it warrants a new release then tag it as v1.0.1 and merge it back into master.

Meanwhile a new development window can be happening on the master branch which will eventually be tagged as v1.1.

Rinse & repeat.

This follows Semantic Versioning numbering logic.

 ---------(v1.0)--------------------------------(v1.1)-----------------------------> master              \                                     \                 ---(v1.0.1)---(v1.0.2)---> 1.0        ---(v1.1.1)---(v1.1.2)---> 1.1 
vote vote


In a VCS, having just a "master" branch shows quickly its limits because you cannot pursue all the development effort at the same time on one branch.
That means you need to know when to branch.

But in a DVCS (as in "Decentralized" VCS), you also have a publication issue, with branches you keep local to your repositories, and branches you are pushing to or pulling from.

In this context, start by identifying your concurrent development effort, and decide on a publication (push/pull) process. For instance (and this is not the only way):

  • prod is a read-only public branch with the code in production. Everyone could pull from it in order to:
    • rebase its current development on top of it (for local testing, or for integrating on the local dev repo a hotfix done in the prod repo on the prod branch)
    • branch to do new features (from a known stable code)
    • branch to start the next release branch (the one which is to be in production)
      no one should push directly to prod (hence the read-only)
  • release is a read-write consolidation branch, where the relevant commits are cherry-picked to be part of the next release.
    Everyone can push to release to update the next release.
    Everyone can pull from said release in order to update his/her local consolidation process.
  • featureX is a private read-write branch (in that it does not need to be push to the central prod repo), and can be pushed/pulled between dev repos. It represents middle to long term effort, different from the daily dev
  • master represents the current dev, and is pushed/pulled between the dev repos.

Other release management processes exist, as this SO question attests.

Top 3 video Explaining Git branch strategy for small dev team