Skip to content

Instantly share code, notes, and snippets.

@RyanSchw
Forked from digitaljhelms/gist:4287848
Last active July 10, 2019 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanSchw/91f6f14fe394545d26bab1ea17133839 to your computer and use it in GitHub Desktop.
Save RyanSchw/91f6f14fe394545d26bab1ea17133839 to your computer and use it in GitHub Desktop.
Git Branching Standards (Simplified)

Branching

This is a simplified branching standard used primarily for internal applications and for companies new to git.

Quick Legend

Instance Branch Description, Instructions, Notes
Working master Accepts merges from Features/Issues
Features feature/ Always branch off HEAD of master
Issues issue/ Always branch off HEAD of master

Main Branch

The main branch should be considered origin/master and will be the main branch where the source code of HEAD always reflects a state with the latest delivered development changes for the next release. As a developer, you will be branching and merging from master.

For simplicity, a stable branch will not be used. Only production-ready-like changes should be made to master. When the master is fully production-ready, then a tag will be created for the commit where the code is released.

Supporting Branches

Supporting branches are used to aid parallel development between team members, ease tracking of features, and to assist in quickly fixing live production problems. Unlike the main branches, these branches always have a limited life time, since they will be removed eventually.

The different types of branches we may use are:

  • Feature branches
  • Bug branches

Each of these branches have a specific purpose and are bound to strict rules as to which branches may be their originating branch and which branches must be their merge targets. Each branch and its usage is explained below.

Feature Branches

Feature branches are used when developing a new feature or enhancement which has the potential of a development lifespan longer than a single deployment. When starting development, the deployment in which this feature will be released may not be known. No matter when the feature branch will be finished, it will always be merged back into the master branch.

During the lifespan of the feature development, the lead should watch the master branch (network tool or branch tool in GitHub) to see if there have been commits since the feature was branched. Any and all changes to master should be merged into the feature before merging back to master; this can be done at various times during the project or at the end, but time to handle merge conflicts should be accounted for.

Working with a feature branch

A feature branch should always be 'publicly' available. That is, development should never exist in just one developer's local branch.

$ git checkout -b feature/description-without-spaces master   // creates a local branch for the new feature
$ git push origin feature/description-without-spaces          // makes the new feature remotely available

Periodically, changes made to master (if any) should be merged back into your feature branch.

$ git merge master                                            // merges changes from master into feature branch

When development on the feature is complete, the lead (or engineer in charge) should merge changes into master and then make sure the remote branch is deleted.

$ git checkout master                                         // change to the master branch  
$ git merge --no-ff feature/description-without-spaces        // makes sure to create a commit object during merge
$ git push origin master                                      // push merge changes
$ git push origin :feature/description-without-spaces         // deletes the remote branch

Bug Branches

Bug branches differ from feature branches only semantically. Bug branches will be created when there is a bug on the live site that should be fixed and merged into the next deployment. For that reason, a bug branch typically will not last longer than one deployment cycle. Additionally, bug branches are used to explicitly track the difference between bug development and feature development. No matter when the bug branch will be finished, it will always be merged back into master.

Although likelihood will be less, during the lifespan of the bug development, the lead should watch the master branch to see if there have been commits since the bug was branched. Any and all changes to master should be merged into the bug before merging back to master; this can be done at various times during the project or at the end, but time to handle merge conflicts should be accounted for.

Working with a bug branch

If the branch does not exist yet (check with the Lead), create the branch locally and then push to GitHub. A bug branch should always be 'publicly' available. That is, development should never exist in just one developer's local branch.

$ git checkout -b bug/description-without-spaces master       // creates a local branch for the new bug
$ git push origin bug/description-without-spaces              // makes the new bug remotely available

Periodically, changes made to master (if any) should be merged back into your bug branch.

$ git merge master                                            // merges changes from master into bug branch

When development on the bug is complete, [the Lead] should merge changes into master and then make sure the remote branch is deleted.

$ git checkout master                                         // change to the master branch  
$ git merge --no-ff bug/description-without-spaces            // makes sure to create a commit object during merge
$ git push origin master                                      // push merge changes
$ git push origin :bug/description-without-spaces             // deletes the remote branch

Workflow Diagram

Git Branching Model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment