How to create a feature branch workflow

· Category: Git

Short answer

Create a branch for each feature, make commits, push the branch, and merge it back through a pull request.

Steps

  1. Create a feature branch from main:
git checkout -b feature/search
  1. Make commits:
git add .
git commit -m "Add search endpoint"
  1. Push and open a pull request:
git push -u origin feature/search
  1. After review, merge via the platform or:
git checkout main
git merge feature/search

Tips

  • Delete feature branches after merging to keep the repo clean.
  • Squash commits if the branch history is messy.
  • Require at least one approval before merging.

Common issues

  • Stale branches: rebase onto main before merging to avoid conflicts.
  • Large features: break them into smaller, reviewable pull requests.