What is the master branch and release branch for?

Learn what is the master branch and release branch for? with practical examples, diagrams, and best practices. Covers git, git-flow development techniques with visual explanations.

Understanding Git's Master and Release Branches

Hero image for What is the master branch and release branch for?

Explore the distinct roles of the master (main) and release branches in Git workflows, their purpose, and how they contribute to a robust software development lifecycle.

In Git-based development, understanding the purpose of different branches is crucial for maintaining a clean, stable, and efficient workflow. Two fundamental branches often encountered, especially in methodologies like Git-Flow, are the master (or main) branch and the release branch. While both are critical for delivering software, they serve distinct purposes in the development and deployment pipeline.

The Master/Main Branch: The Source of Truth

The master (now commonly referred to as main) branch is traditionally considered the definitive history of your project's official release. It represents the production-ready state of your software. Every commit on this branch should ideally correspond to a version that has been, or is ready to be, deployed to users. It's a highly stable branch, and direct commits to it are generally discouraged in favor of merging well-tested code from other branches.

The Release Branch: Preparing for Deployment

A release branch is a temporary, dedicated branch created when the development team is ready to prepare a new version of the software for release. It branches off from the develop branch (in Git-Flow) or directly from main if a simpler model is used. The primary purpose of a release branch is to allow for final preparations, bug fixes, and last-minute tweaks specific to that release without disrupting ongoing development on the develop branch.

flowchart TD
    A[Start Development] --> B(Develop Branch)
    B --> C{Feature Development}
    C --> B
    B --"Ready for Release"--> D[Create Release Branch]
    D --> E(Release Branch)
    E --"Bug Fixes & Prep"--> E
    E --"Release Complete"--> F[Merge to Main]
    F --> G[Tag Release]
    F --> B
    G --> H[Production]

Simplified Git-Flow illustrating master and release branch interaction

Once a release branch is created, only critical bug fixes and release-specific changes are committed to it. New features are strictly prohibited. After the release is deemed stable and ready, the release branch is merged into main (to record the official release history) and often also back into develop (to ensure any bug fixes made on the release branch are carried forward into future development). Finally, the main branch is tagged with the release version number (e.g., v1.0.0).

Key Differences and Workflow

The fundamental difference lies in their stability and purpose. The main branch is the long-lived, perpetually stable branch representing deployed code. The release branch is a short-lived, temporary branch used for stabilizing a specific version before it becomes the next main branch state. This separation allows development to continue uninterrupted on new features while a specific version undergoes final testing and hardening.

# Example Git-Flow commands for release branch

git flow release start 1.0.0
# ... make bug fixes, update documentation ...
git commit -am "Fix: Critical bug in login module"

git flow release finish 1.0.0

Basic Git-Flow commands for managing a release branch.