Git branch strategy for small dev team

GitBranchGit Branch

Git Problem Overview


We have a web app that we update and release almost daily. We use git as our VCS, and our current branching strategy is very simple and broken: we have a master branch and we check changes that we 'feel good about' into it. This works, but only until we check in a breaking change.

Does anyone have a favorite git branch strategy for small teams which meets the following requirements:

  1. Works well for teams of 2 to 3 developers
  2. Lightweight, and not too much process
  3. Allows devs to isolate work on bug fixes and larger features with ease
  4. Allows us to keep a stable branch (for those 'oh crap' moments when we have to get our production servers working)

Ideally, I'd love to see your step-by-step process for a dev working on a new bug

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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 http://nvie.com/posts/a-successful-git-branching-model/ 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 github.com as the central place to pull the latest code.

Solution 3 - Git

(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: http://scottchacon.com/2011/08/31/github-flow.html

Note that "pull requests" are a Github invention, and it's something that's baked into their website, not Git itself: https://help.github.com/articles/using-pull-requests/

Solution 4 - Git

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

Solution 5 - Git

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.

Solution 6 - Git

Read through ReinH's Git Workflow for Agile teams here: http://reinh.com/blog/2009/03/02/a-git-workflow-for-agile-teams.html

This works very well for small teams. The goal here is to make sure everything that might be potentially unstable goes in to a branch of some kind. Only merge back to master when you are ready for everyone working outside of the feature branch to use it.

Note: this strategy is hardly git specific, but git makes implementing this strategy pretty easy.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBilal and OlgaView Question on Stackoverflow
Solution 1 - GitJimmyView Answer on Stackoverflow
Solution 2 - GitClutchView Answer on Stackoverflow
Solution 3 - Gitprogram247365View Answer on Stackoverflow
Solution 4 - GitLeif GruenwoldtView Answer on Stackoverflow
Solution 5 - GitVonCView Answer on Stackoverflow
Solution 6 - GitwhaleyView Answer on Stackoverflow