Engineering Craft › Branching & Releases
Feature Branch
A short-lived branch for one change.
Also known as: feature branches, topic branch, short-lived branch
A feature branch is a short-lived branch created to do one piece of work, such as a feature, a fix or an experiment, separate from the main line. When it’s done and reviewed, it’s merged back and deleted.
git switch main
git pull
git switch -c feat/export-csv # start from an up-to-date main
# ...commit as you go...
git push -u origin feat/export-csv
# open a pull request, get review, merge, delete the branch
Why use them
- Isolation: unfinished work doesn’t break
mainor other people’s work. - A natural unit for review. One branch becomes one pull request.
- Easy to abandon or park: delete the branch.
- Parallel work by several people.
Keep them short
The longer a branch lives, the further it drifts from main, and the more painful merging becomes (merge conflicts). Aim for days, not weeks.
- Make the change small (small PRs), and split big features into pieces that can merge one at a time.
- Merge or rebase
maininto your branch regularly to stay current (merge vs rebase). - Use feature flags to merge unfinished work safely, hidden from users, when a feature can’t be done in a few days (feature flags).
Habits
- Name it clearly (branch naming).
- One purpose per branch.
- Delete it after merging. The commits are safe in
main. - Don’t build a branch on top of another unmerged branch unless you mean to (stacked PRs).
Teams that merge to main many times a day sometimes skip long-lived feature branches entirely (trunk-based development). Feature branches are the common middle ground (GitHub flow).