W3docs

Feature branch workflow

Learn the feature branch workflow — develop each change on its own branch and merge it back to main through review. Step-by-step example.

Overview

The feature branch workflow is the most common way teams collaborate with Git. The rule is simple: all development happens on dedicated branches, never directly on main. Each new feature, fix, or experiment gets its own branch, and the main branch only ever receives finished, reviewed work. This keeps main stable and releasable at all times.

Feature branches diverging from main and merging back after review

The core idea

Because work is isolated on branches, several people can build different features in parallel without interfering. main acts as the single source of truth for production-ready code. A branch is a focused unit of work that has a clear beginning (created from main) and end (merged back into main).

A step-by-step example

Start from an up-to-date main and create a branch for your task:

git switch main
git pull
git switch -c feature/login-form

Do your work, committing as you go:

git add .
git commit -m "Add login form markup and validation"

Push the branch so others can see it and so you can open a pull request:

git push -u origin feature/login-form

Review and merge

On a hosting platform such as GitHub or GitLab, you open a pull request (or merge request). This is where teammates review the diff, leave comments, and approve. CI typically runs the test suite against the branch automatically. Once approved and green, the branch is merged into main — often with a squash so the feature lands as a single tidy commit.

After merging, delete the branch to keep the repository clean:

git switch main
git pull
git branch -d feature/login-form

Keeping a branch current

If main moves ahead while you work, bring those changes into your branch so the eventual merge is smooth. You can merge main into your branch, or rebase your branch onto the latest main for a linear history:

git switch feature/login-form
git rebase main

Benefits and trade-offs

The feature branch workflow is popular because it is easy to understand, integrates naturally with pull requests and code review, and keeps main clean. Its main risk is long-lived branches: the longer a branch lives, the more it diverges from main and the harder the merge. Keep branches small and short, and merge often.

Practice

Practice

Which statements describe the feature branch workflow correctly?