Feature Branch Workflow
Do all work on short-lived branches and merge into main through pull requests.
The feature branch workflow is the everyday routine used by most teams:
- Start from an up-to-date
main. - Create a descriptive branch, e.g.
feature/search-bar. - Commit small, focused changes.
- Push and open a pull request.
- Review, then merge and delete the branch.
main stays deployable at all times because unfinished work lives on branches.
Example
git switch main
git pull # start fresh
git switch -c feature/search-bar
# ...commit as you go...
git push -u origin feature/search-bar
# open a PR, get it reviewed, merge, then:
git switch main && git pull
git branch -d feature/search-barWhen to use it
- A five-person team each owns a separate feature branch, so no one's work-in-progress can break anyone else's daily build.
- A developer creates feature/checkout to add a checkout flow, merges it via PR, then immediately starts feature/tracking on a fresh branch.
- A team enforces that main is always deployable by requiring all changes to arrive through reviewed, tested feature branches.
More examples
Start a new feature branch
Pulls the latest main before branching to ensure the feature starts from the most up-to-date stable base.
# Always branch from a fresh main
git switch main
git pull origin main
git switch -c feature/checkout-flowWork, commit, and push the feature
Demonstrates making multiple small, focused commits on the feature branch before pushing to open a pull request.
# Develop the feature with focused commits
git add src/checkout.js tests/checkout.test.js
git commit -m "feat: add cart total calculation"
git add src/checkout.js
git commit -m "feat: add stripe payment step"
git push -u origin feature/checkout-flowOpen PR and clean up after merge
Completes the full feature branch lifecycle: open a PR, merge it, then delete the local branch to stay organised.
gh pr create --title "feat: checkout flow" --base main
# After PR is merged:
git switch main
git pull origin main
git branch -d feature/checkout-flow
Discussion