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
- Create a feature branch from
main:
git checkout -b feature/search
- Make commits:
git add .
git commit -m "Add search endpoint"
- Push and open a pull request:
git push -u origin feature/search
- 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
mainbefore merging to avoid conflicts. - Large features: break them into smaller, reviewable pull requests.