Patterns

Git Release Branch

Release Branch Workflow

Git release branch prepares code for production deployment.

What is a Git Release Branch?

A Git release branch is an essential part of the Git workflow, specifically designed for preparing code for production deployment. It serves as a bridge between development and production environments, ensuring that new features and improvements are thoroughly tested and stable before being released to users.

The release branch is created from the main branch (often main or master), and it remains in existence until the release is finalized. This branch allows developers to polish the release, fix minor bugs, and prepare release notes without affecting ongoing development in the main branch.

Creating a Git Release Branch

To create a release branch, you typically branch off from the main branch. It's common to include the version number in the branch name for clarity. Here's a step-by-step guide:

In this example, we have created a release branch named release/1.0.0. This branch will be used to finalize the release, including bug fixes and last-minute polish.

Working on a Release Branch

Once the release branch is created, developers can work on fixing minor bugs, optimizing performance, and preparing the application for deployment. Unlike the feature branches, no new features are added to this branch to maintain stability.

Developers can commit changes directly to the release branch:

Merging Release Branch into Main

Once the release is finalized and tested, the release branch is merged back into the main branch. This ensures that all the updates are included in the main branch for future developments.

First, you should ensure the release branch is up to date with any changes from the main branch:

Then, merge the release branch into the main branch:

The --no-ff flag ensures that the merge commit is created, preserving the history of the release branch.

Tagging a Release

After merging, it's a good practice to tag the release in the repository. Tags are used to mark specific points in history as important:

This command tags the current commit with v1.0.0, making it easy to identify the release point in the project history.

Deleting the Release Branch

Once the release has been tagged, you can safely delete the release branch from the remote repository to keep it clean:

This ensures that your repository remains organized, with only active branches present.