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:

  1. Start from an up-to-date main.
  2. Create a descriptive branch, e.g. feature/search-bar.
  3. Commit small, focused changes.
  4. Push and open a pull request.
  5. Review, then merge and delete the branch.

main stays deployable at all times because unfinished work lives on branches.

Example

Example · bash
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-bar

When 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.

Example · bash
# Always branch from a fresh main
git switch main
git pull origin main
git switch -c feature/checkout-flow

Work, commit, and push the feature

Demonstrates making multiple small, focused commits on the feature branch before pushing to open a pull request.

Example · bash
# 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-flow

Open 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.

Example · bash
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

  • Be the first to comment on this lesson.