Foundations: Web, Git, and Command Line
Establish core web concepts, version control fluency, and developer tooling fundamentals for a productive workflow.
Content
Branching Strategies
Versions:
Watch & Learn
AI-discovered learning video
Branching Strategies: Choose Your Own Git Adventure (Without Summoning Merge Conflicts)
"A branch is not a vibe. It’s a plan." — someone who learned the hard way on a Friday at 4:59 PM
You’ve already tangoed with commits, remotes, and pull requests in Git Essentials, and you’ve pointed DNS records at hosting so the internet can find your app without needing a treasure map. Now it’s time to decide how your team’s code moves from idea to production without turning main into a haunted house.
This is the art (and mild chaos) of branching strategies. Think of it like traffic patterns for your repo: you can do roundabouts, express lanes, or the occasional country road. The goal: ship fast, ship safely, and don’t ship bugs named “untitled-final-FINAL.js.”
What Even Is a Branch? (Micro-recap)
- A branch is a movable pointer to a commit history. It lets you experiment without kneecapping stable code.
- Merging combines histories; rebasing rewrites history so your branch looks like it started from a different commit. Use wisely.
- The main branch (often
main) is usually “the thing we’d be okay deploying to production right now.” Your DNS and hosting setup from earlier? That’s the stage wheremaintakes a bow.
The Big Three Strategies (And When To Use Them)
1) Trunk-Based Development (TBD)
- Core idea: Everyone branches off
main(aka the trunk), does small changes, and merges back quickly — often multiple times per day. - Branches are short-lived (hours to a couple days). Long-lived branches are suspicious like Tupperware in the office fridge.
- Commonly uses feature flags to hide incomplete work in production.
ASCII vibe check:
main: o--o--o--o--o--o
\ \ \ \ \
feature: o o o o o (merge back fast)
- Best for: Rapid web services, continuous deployment, teams comfortable with CI.
- Pros: Fast feedback, fewer merge nightmares, deploy like a Netflix show drops episodes — constantly.
- Watch-outs: Requires discipline, strong automated tests, and feature flags.
2) GitHub Flow
- Core idea:
mainis always deployable. Create a feature branch, open a PR, get review, merge tomain, deploy. - No dedicated
developbranch. It’s lightweight and social (PRs are the party).
main ----o----o----o----o
\feature-x---(PR)--/
- Best for: Web apps with frequent releases, small to medium teams.
- Pros: Simple, encourages code review, works great with CI/CD.
- Watch-outs: If your PRs get too big, you will time-travel to Merge Conflict City.
3) Git Flow
- Core idea: You have
main(production),develop(integration), plusfeature/*,release/*, andhotfix/*branches.
main ----o------o--------o----
\ / \
hotfix / tag
develop o--o--o--o--o--o--o--o--o
\ \
feature release
- Best for: Products with formal, versioned releases (mobile apps, on-prem software).
- Pros: Structured, clear release process; hotfix isolation.
- Watch-outs: Heavier process; slower;
developcan drift like a teenager’s attention span.
Quick Comparison Table
| Strategy | Best For | Branches | Release Cadence | Pros | Watch-outs |
|---|---|---|---|---|---|
| Trunk-Based | High-frequency deploys | main + short-lived features |
Continuous | Speed; tiny PRs; fewer conflicts | Needs strong CI + feature flags |
| GitHub Flow | Web services, small/med teams | main + features via PRs |
Frequent | Simple; PR-focused | Big PRs hurt; discipline needed |
| Git Flow | Versioned products | main, develop, feature/*, release/*, hotfix/* |
Batches | Clear releases; hotfix path | Process overhead; slower |
Mapping Branches to Environments (Hi Again, DNS + Hosting)
You already pointed a domain to production. Add staging and preview like a pro.
| Branch | Environment | URL Example |
|---|---|---|
main |
Production | https://app.example.com |
develop (Git Flow) or staging |
Staging | https://staging.example.com |
| Feature branches | Preview deploys | https://pr-128.example.com |
- CI/CD can auto-deploy
mainto production,developto staging, and PR branches to ephemeral previews. - DNS tip: Use subdomains (CNAMEs) for staging and preview; keep production pristine.
Merge, Rebase, Squash: The Love Triangle
- Merge commit: Preserves full history, creates a merge node. Good for teams that like history intact.
- Rebase: Makes a clean, linear history. Use on your feature branch before PR to avoid merge spaghetti. Never rebase public
main. - Squash merge: Combines your whole PR into one tidy commit. Ideal for keeping
mainreadable.
Example (safe) feature rebase:
# Update your feature with latest main
git checkout feat/login-oauth
git fetch origin
git rebase origin/main
# Resolve conflicts, continue
git rebase --continue
Naming Conventions (A Small Change That Saves Big Sanity)
- Use prefixes:
feat/,fix/,chore/,docs/,perf/,refactor/,hotfix/,release/. - Include ticket ID:
feat/123-oauth-login - Example:
git checkout -b feat/456-improve-image-cache
Protect important branches:
- Protect
main(anddevelopif using Git Flow). - Require PR reviews and passing checks.
- Block force-pushes to protected branches.
How To Actually Run Each Strategy (Step-by-step)
GitHub Flow (lightweight, most common)
- Branch off main:
git checkout -b feat/789-comment-replies
- Commit small, focused changes. Push and open PR:
git push -u origin feat/789-comment-replies
- Keep branch fresh:
git fetch origin && git rebase origin/main
- PR review, run CI, squash-merge to main. CI auto-deploys to prod.
Trunk-Based (fast and furious)
- Keep branches tiny. Feature flag unfinished UI.
- Rebase often; merge daily or more.
- Deploy frequently; monitor like a hawk.
Feature flag pattern (pseudo):
if (features.newCheckout) {
renderNewFlow();
} else {
renderOldFlow();
}
Git Flow (structured releases)
- Integrate on
develop. - Start a release when stable:
git checkout develop
git checkout -b release/1.5.0
- Stabilize release; then:
# Finish release: merge to main, tag, and back-merge to develop
git checkout main
git merge --no-ff release/1.5.0
git tag -a v1.5.0 -m "Release 1.5.0"
git checkout develop
git merge --no-ff release/1.5.0
git branch -d release/1.5.0
- Hotfix urgent prod issues from
main:
git checkout -b hotfix/1.5.1
# fix, test
git checkout main
git merge --no-ff hotfix/1.5.1
git tag -a v1.5.1 -m "Hotfix: patch auth crash"
git checkout develop
git merge --no-ff hotfix/1.5.1
git branch -d hotfix/1.5.1
Picking Your Strategy (Decision Cheatsheet)
Ask:
- How often do we release? Daily or hourly → Trunk/GitHub Flow. Monthly with formal versions → Git Flow.
- What’s our test coverage? Strong → Trunk okay. Weak → Git Flow might protect you (but write tests anyway).
- Do we need hotfix isolation and version tags? If yes → Git Flow.
- Team size and experience? Newer or distributed teams often benefit from GitHub Flow’s simplicity.
Rule of thumb: Start with GitHub Flow. Add release branches only when you need them. Avoid inventing a 72-page branching constitution.
Common Pitfalls (a.k.a. How Repos Become Cryptids)
- Monster PRs: If your PR needs a table of contents, it’s too big. Slice it.
- Long-lived feature branches: Conflicts will find you. Merge or rebase frequently.
- Unprotected main: One force-push and your CI will cry.
- Branch-per-person: No. Branch-per-thing. Humans take vacations; features don’t.
- "We’ll fix it in production": That’s not a strategy. That’s a documentary.
Real-World Analogy: Restaurant Kitchen
mainis the menu that customers see. Stable, appetizing.- Feature branches are test dishes. You try them on staff (preview deploys) before unleashing on brunch crowd chaos.
- Git Flow’s
release/*is the seasonal menu: you finalize it before printing. - Trunk-Based is the chef’s tasting menu that evolves constantly — tiny, frequent changes, but the kitchen is a test powerhouse.
Pro Tips That Pay Rent
- Automate checks: lint, tests, type checks, accessibility audits.
- Use conventional commits or PR titles for auto-changelog:
- feat: add OAuth login
- fix: handle 401 refresh
- Require at least one approving review on
main. - For DNS/hosting: map staging to
develop(if used) and enable preview URLs on PRs so reviewers can click reality, not imagine it.
TL;DR + Send-off
- Branching strategies are social contracts that keep code flowing and production chill.
- GitHub Flow: simple, PR-centric, great default.
- Trunk-Based: ultra-fast, needs strong CI and feature flags.
- Git Flow: structured releases, best for versioned products and hotfix rigor.
- Protect
main, keep PRs small, and rebase your feature branch (notmain) to stay conflict-lite.
Final wisdom: Branches don’t make you safe — habits do. Choose a strategy, write tests, set protections, and let CI be your bouncer.
Now go configure those branch protection rules, wire CI to your hosting, and make main the calm, production-ready legend it was born to be.
Comments (0)
Please sign in to leave a comment.
No comments yet. Be the first to comment!