Git Workflows (GitFlow, Trunk-based)
Branching models standardize how a team integrates work. GitFlow uses main, develop and release/hotfix branches for scheduled releases; GitHub Flow keeps everything on short-lived branches off main; trunk-based development commits small changes to main constantly with strong CI and feature flags.
What is this?
Git workflows define which branches exist and how work flows between them. GitFlow maintains parallel main (production) and develop branches with feature, release and hotfix branches. GitHub Flow works from a single main branch with short feature branches merged via pull requests. Trunk-based development treats main as the trunk that everyone integrates into, often multiple times a day.
Why do you need it?
- A defined workflow makes every merge predictable and releases reproducible.
- It encodes process: where features, releases and hotfixes enter the codebase.
- It balances stability (protection of main) against velocity (how fast work ships).
- It plugs directly into CI/CD gates such as required checks and deployment triggers.
Mental model
Traffic rules on a highway
A git workflow
Rules keep traffic flowing at the speed the team chooses. No rules means chaos; too many rules means gridlock. GitFlow is the slow lane, trunk-based the express lane.
How it works
- GitFlow: features branch from and merge into develop; release branches cut from develop, stabilized, and merged to both main and develop; hotfixes branch from main and merge back to both.
- GitHub Flow: every change starts as a short-lived branch off main; a pull request reviews it; merging to main triggers a deploy.
- Trunk-based: developers integrate to main constantly, using small commits and feature flags instead of long-lived branches.
- Releases in trunk-based can be branch or tag cuts from main when you ship.
- All workflows rely on branch protection and CI checks to keep main green.
Branches in the GitFlow model.
Key commands
git switch -c feature/loginStart a feature branch off the current base.
git merge --no-ff developForce a merge commit so feature work stays visible in history.
git tag -a v1.0.0 -m 'Release 1.0.0'Tag a release commit for traceability.
git switch -c hotfix/1.0.1 mainCut a hotfix branch from main in GitFlow.
git push origin --delete feature/loginDelete a remote branch after it is merged.
Examples
GitHub Flow in five commands
git switch -c feature/login# ... implement and commit ...git push -u origin feature/login# Open a pull request on GitHub → review → merge to maingit switch maingit pullgit branch -d feature/loginA short-lived feature branch is pushed and merged through a reviewed pull request, main is updated, and the branch is deleted. This is the entire GitHub Flow loop, repeated many times a day.
In production
- GitFlow suits products with scheduled releases and a stable, supportable main.
- Trunk-based development fits continuous delivery teams deploying many times a day.
- GitHub Flow works well for product teams deploying continuously with short-lived PRs.
- Release branches (or tags) freeze a version for stabilization and backporting.
Best practices
- Match the workflow to your release cadence — do not adopt GitFlow ceremony for daily deploys.
- Protect main with required pull request review and passing CI before merge.
- Keep feature branches short; long-lived branches are the enemy of every workflow.
- In trunk-based work, rely on feature flags and strong automated tests, not long-lived branches.
- Document the chosen workflow in CONTRIBUTING.md so everyone follows the same rules.
Common mistakes
- Adopting GitFlow for a team that deploys continuously, adding pointless release ceremony.
- Letting release branches drift far from main and develop, causing painful merges.
- Committing directly to main without CI or review in trunk-based setups.
- Running mixed workflows in one repo so nobody knows where a branch belongs.
Common issues
Massive conflicts merging a release branchRelease branch drifted from develop/main for weeks.
Merge or rebase develop into the release branch regularly during stabilization.
Hotfix merged to main but lost on developGitFlow requires merging hotfixes into both branches and only one was done.
Merge or cherry-pick the hotfix commit into develop as well.
Deploy fired for a feature commit meant for a later releaseThe deploy trigger is 'push to main' with no release gating.
Gate deploys on tags or a release branch instead of raw main pushes.
Debugging tips
- git log --oneline --graph to audit whether merges follow the intended structure.
- git branch -a to see local and remote branches and spot strays.
- Check CONTRIBUTING.md for the repository's expected branch flow.
- git reflog to recover when a release or hotfix merge went wrong.
Interview checkpoint
Quick quiz
In GitFlow, which branch holds production-ready code?
Trunk-based development encourages long-lived feature branches.
In GitFlow, a hotfix branch should be cut from which branch?
Cheat sheet
git switch -c feature/xGitFlow/GitHub Flow feature startgit switch -c release/1.0.0 developCut a release from developgit switch -c hotfix/1.0.1 mainCut a hotfix from maingit merge --no-ff developVisible merge commitgit tag -a v1.0.0 -m 'msg'Tag a releasegit push origin --delete branchDelete remote branch