Feature-Branch Workflow and Best Practices
10 min read
The Feature-Branch Workflow
The feature-branch workflow is the standard at most professional teams including CPCODELAB. main is always deployable. All work happens on short-lived feature branches that are reviewed and merged via pull requests.
Daily Workflow Checklist
- Start the day:
git fetch originthengit rebase origin/mainon your branch. - Work in small, focused commits — one logical change per commit.
- Push to your remote branch frequently:
git pushafter every meaningful commit. - Before opening a PR: rebase, run the test suite, review your own diff on GitHub.
- After your PR is merged:
git switch main,git pull, delete the old branch.
Best Practices Summary
- Commit early, commit often — small commits are easier to review, bisect, and revert.
- Pull (or fetch + rebase) often — stay close to
mainto minimise conflict surface. - Never commit secrets —
.envfiles, API keys, and passwords never belong in Git. - Write meaningful messages — future-you and your teammates will thank you.
- Keep branches short-lived — long-running branches diverge and become painful to merge.
- Review your diff before committing —
git diff --stagedcatches embarrassing mistakes. - Use `--force-with-lease` not `--force` — safer when force-pushing feature branches.
git bisect — Finding Bugs with Binary Search
When a bug appears and you don't know which commit introduced it, git bisect performs a binary search through history. You mark a known-good commit and a known-bad commit, and Git checks out the midpoint for you to test.
bash
git bisect start
git bisect bad # current commit is broken
git bisect good v1.0.0 # v1.0.0 was fine
# Git checks out a middle commit — test it, then:
git bisect good # or: git bisect bad
# Repeat until Git identifies the first bad commit
git bisect reset # return to HEAD when doneConsistent, small, focused commits make git bisect extremely effective. If each commit represents one logical change, bisect pinpoints the exact commit that introduced a regression rather than a large blob of changes.
Ready to test yourself?
Practice Git & GitHub— quiz & coding exercises