# Git Flow

By

It describes a best practice branching model and follows essentially the GitHub Flow.

# Flow overview

# Branches overview

Branch created from merge back to protected
main -- -- YES
develop main main YES
release develop develop, main NO
feature develop develop NO
bugfix develop develop NO
hotfix main develop, main NO

# Which branch serves which function?

The main and develop branches are long-running branches with protection rules. The rules ensure that every change is code reviewed, along with ensuring passing tests in the CI environment before changes go in.

# main

Represents the current state of production environment. It should always reflect the stable and deployable code.

# develop

This branch serves as integration branch for ongoing development work. It contains pre-production code with newly developed features and bugfixes.

# release

When the next release date is approaching the develop branch forks a release branch. From this point on, no new features should be added to this branch, only bugfixes. When it is ready for delivery, the release branch is merged into the main branch tagged with a version number (rocket's semantic release management automates this). Additionally it should be merged back into the develop branch, which may have evolved since the release was initiated.

# feature

Are used for developing new features. Each new feature should be developed in a separate branch independent from other features. Several feature branches can be worked on simultaneously.

# bugfix

Bugfix branches are used to fix bugs in the code that are not urgent and critical. They are treated like feature branches but with another prefix.

# hotfix

Hotfix branches are used to fix critical bugs in production environment. Using these should be the exception. Merging such a branch triggers the creation of a new tag on the main branch.

# Naming conventions

# Basic Rules / Best practices

  • Use prefixes to categorize branch (see table below)

  • Lowercase and Hyphen-separated: Stick to lowercase for branch names and use hyphens to separate words. For instance, feat/PROJECT-123-new-login or bugfix/PROJECT-123-header-styling.

  • Use only alphanumeric characters (a-z, 0–9) and hyphens. Avoid punctuation, spaces, underscores, or any non-alphanumeric character.

  • Do not use continuous hyphens. feat--new-login can be confusing and hard to read.

  • The name should be descriptive and concise, ideally reflecting the work done on the branch.

# Examples

Branch type Name
feature feat/LHAC-[TicketNr]-aaaa-bbb
bugfix bugfix/LHAC-[Ticket-Nr]-aaaa-bbb
hotfix hotfix/LHAC-[Ticket-Nr]-aaaa-bbb
release release/sprint-[Sprint-Nr]

# Create branches

# Feature branch - develop a new feature

When starting work on a new feature, branch off from the develop branch.

  1. Make sure your develop branch is up-to-date

  2. Create a feature branch based off of develop

$ git checkout develop
$ git checkout -b feat/PROJECT-123-new-feature
$ git push --set-upstream feat/PROJECT-123-new-feature
  1. Develop the code for the new feature and commit. Push your changes often. This allows others to see your changes and suggest improvements/changes as well as provides a safety net should your hard drive crash.

  2. Open a pull request with the following branch settings:

  • Base: develop
  • Compare: feat/PROJECT-123-new-feature
  1. When the pull request was reviewed, merge and close it and delete the feat/PROJECT-123-new-feature branch.

# Hotfix branch - fix a critical bug in production environment

  1. Make sure your local main branch is up to date.
  2. Create a hotfix branch based off of main
$ git checkout main
$ git checkout -b hotfix/PROJECT-123-hotfix-issue
$ git push --set-upstream hotfix/PROJECT-123-hotfix-issue
  1. Fix the critical bug code, commit and push. The commit message should be of type "fix".
$ git add --all
$ git commit -m 'fix(scope): [hotfix-issue]'
$ git push
  1. Open two pull requests with the following branch settings:
  • Base main - Compare: fix/PROJECT-123-hotfix-issue

  • Base develop - Compare: fix/PROJECT-123-hotfix-issue (TODO: automate this one?)

  1. When the pull requests was reviewed, merge and close it and delete the hotfix branch.