Skip to content

Branching

The Basics

Branch Management

Gitflow Workflow

Creating and Merging Branches (YouTube video)

Gitflow Branching

At B&R we follow the Gitflow branch strategy:

  • Two long-living branches:
    • main
      • Officially released code
      • As bug-free as possible
      • Each merge into main must be tagged with a version number
      • There is only 1 instance of the main branch, and it is never deleted
    • develop
      • Integration branch for new features
      • Latest development version ready for testing (may contain bugs)
      • Should compile and run on real hardware
      • There is only 1 instance of the develop branch, and it is never deleted
      • Create a release branch from the develop branch once you are ready to prep for release
  • Supporting branches (temporary):
    • feature
      • Used for developing new features
      • Several feature branches can exist simultaneously
      • Can be both local and remote
      • Useful anytime you expect to commit multiple times for one particular feature, even if the feature is completed within a short period of time
      • Merged back into develop after the feature has been reviewed and it is ready for integration testing. Then the branch is deleted.
    • release
      • branched from develop once all planned bugs/features are merged for the next release
      • Only used for bug fixes, documentation, and other release oriented tasks (no new features)
      • Merged back into main and develop once testing is complete and discovered bugs are fixed. Then the branch is deleted.
    • hotfix
      • Branched from main when critical bug found in production that must be solved immediately
      • Used to develop critical bugfixes
      • Merged back into main and develop. Then the branch is deleted.

Manual vs Git-flow

You can use the icons at the top of Sourcetree to manually branch and merge according to the strategy previously described.

Alternatively, you can use the Git-flow icon in the top right. Git-flow guides you to follow the branching strategy with a simple GUI. This is the recommended method.

Git-flow

When you first launch Git-flow, you must initialize the repo for Git-flow. Remember to change the production branch name to "main" ("master" is the default value).

After initialization, click the "Git-flow" icon again to start a new action.

As application engineers, you will typically select the "Start New Feature" action. The project lead will start the release or hotfixes.

Git-flow Feature

When you start a new feature, give it a name and then confirm that it starts at the "develop" branch.

Commit and push to your feature branch as needed during development.

Execute a code review (more on this later).

Once complete and reviewed, click the "Git-flow" icon again and select "Finish Feature". This will merge the feature branch back into develop for you and delete the feature branch.