Git Feature Branch Cheat Sheet
Quick reference for a production-grade feature-branch workflow: commands, naming, conventions, and best practices — copy/paste into your docs or blog.
Branching model (common)
main — Production-ready, always stable.
develop (optional) — integration before staging.
feature/... — short-lived feature or bugfix branches.
release/ — final testing and prep for production.
hotfix/ — urgent fixes applied to
develop (optional) — integration before staging.
feature/... — short-lived feature or bugfix branches.
release/ — final testing and prep for production.
hotfix/ — urgent fixes applied to
main.
Common commands (step-by-step)
# sync with remote main
git checkout main
git pull origin main
# create feature branch (name using prefix/short-desc)
git checkout -b feature/add-user-auth
# stage & commit changes
git add .
git commit -m "feat(auth): add login API with Supabase integration"
# push branch to remote
git push -u origin feature/add-user-auth
# keep your branch up-to-date (merge or rebase)
git fetch origin
git rebase origin/main # (or: git merge origin/main)
# delete local & remote branch after merge
git branch -d feature/add-user-auth
git push origin --delete feature/add-user-auth
Pull Requests & Merging
1. Open a PR from
2. Ensure CI passes (unit + integration + e2e as configured).
3. Request 1–2 reviews, address comments, squash/rebase if needed.
4. Merge using GitHub’s "Merge" (merge commit), "Squash and merge", or "Rebase and merge" per team policy.
feature/… → main (or develop).
2. Ensure CI passes (unit + integration + e2e as configured).
3. Request 1–2 reviews, address comments, squash/rebase if needed.
4. Merge using GitHub’s "Merge" (merge commit), "Squash and merge", or "Rebase and merge" per team policy.
Naming conventions
Branch prefixes:
Example:
feature/, fix/, chore/, hotfix/.Example:
feature/add-user-auth
Commit message style (Conventional Commits)
(scope?): short description # examples feat(auth): add login API with Supabase fix(profile): correct avatar upload path chore(ci): speed up GitHub Actions cache
Repo layout (monorepo example)
repo-root/
├── apps/
│ ├── web/ # Next.js frontend
│ ├── mobile/ # React Native / Expo
│ └── admin/ # Admin dashboard
├── packages/
│ ├── ui/ # shared UI components
│ ├── db/ # migrations & schema
│ └── config/ # shared config & env helpers
├── .github/ # CI workflows (GitHub Actions)
├── supabase/ # Supabase migrations & seed scripts
├── package.json
└── README.md
Best practices & tips
- Keep feature branches small and focused — aim for quick reviews.
- Run tests locally before pushing; CI should run full test suite.
- Version database migrations and test them in staging before production.
- Use protected branches for
main(require PR reviews, passing CI). - Prefer draft PRs to share early progress without blocking reviewers.
- Rebase interactively to keep history clean when appropriate (
git rebase -i). - Have rollback plans for code and DB migrations (down-scripts or reversible migrations).
Quick aliases (optional)
# add to ~/.gitconfig under [alias]
co = checkout
br = branch
ci = commit
st = status
undo = reset --soft HEAD~1
Need a printable one-page PDF or a PNG of this snippet? I can generate and export it for your docs.
Comments
Post a Comment