Use a dev branch so main stays deployable
If main is what's actually running in production, committing straight to it means every half-finished change is one push away from breaking things for real users. Doing the work on a dev branch instead gives you a safe place to build and break things, and turns "shipping" into a deliberate step — merging into main — instead of an accident.
-
Why not just commit to main?
mainshould always be in a state you'd be comfortable deploying right now. Committing feature work directly to it means every in-progress change — an untested query, a half-wired UI, a broken migration — sits on the same branch your deploy pipeline watches. Adevbranch (or one branch per feature) gives that work somewhere to live until it's actually done, without ever puttingmainat risk. -
Create the dev branch from main
Start from an up-to-date
main, then branch off it.-bcreates the branch and switches to it in one step.git checkout main git pull origin main git checkout -b dev git push -u origin devThe last line publishes
devto the remote and links your local branch to it, so plaingit pushandgit pullwork from here on. -
Do the actual work on dev
Everything — new features, refactors, risky experiments — happens on
dev(or a branch cut from it). Commit as often as makes sense;mainnever sees any of this until you decide it's ready.git add . git commit -m "Add checkout validation" git push -
Merge dev into main when it's ready
Once
devis tested and you actually want it live, merge it intomain— not the other way around.--no-ffkeeps a merge commit even if the merge could fast-forward, so your history still shows where each round of work landed.git checkout main git pull origin main git merge --no-ff dev -m "Merge dev: checkout validation" git push origin mainThis is also the natural place for a pull request instead of a local merge — same idea, but with review and CI running against
devbefore it touchesmain. -
Bring dev back up to date
After
mainmoves — from this merge, a hotfix, or anyone else's work — sync those changes back intodevbefore you keep building, so you're never merging a badly outdated branch later.git checkout dev git merge main git pushRepeat from step 3: build on
dev, merge intomainwhen ready, sync back —mainstays deployable at every point in between.