Git is the backbone of modern software development. But knowing git commit and
git push is just the beginning. The real power lies in adopting a structured
branching workflow that keeps your codebase clean, your team synchronized, and
your deployments safe.
Why a Workflow Matters
Without a defined workflow, teams often face: merge conflicts on main, half-finished
features deployed to production, no clear history of what was released when, and difficulty
rolling back bugs. A good workflow eliminates all of this.
1. Feature Branch Workflow
The simplest and most widely used approach. Every new feature or bugfix gets its own branch:
# Create a feature branch
git checkout -b feature/user-authentication
# Work, commit, push
git add .
git commit -m "feat: add JWT-based user auth"
git push origin feature/user-authentication
# Open a Pull Request → Code Review → Merge to main
Rule: Never commit directly to main. All changes go through Pull
Requests with at least one reviewer.
2. GitFlow — For Structured Releases
GitFlow is ideal for projects with scheduled release cycles. It uses a set of permanent and temporary branches:
main— production-ready code onlydevelop— integration branch for completed featuresfeature/*— individual features, branch offdeveloprelease/*— release preparation, branch offdevelophotfix/*— urgent patches, branch offmain
# Start a feature
git flow feature start user-dashboard
# Finish a feature (merges to develop automatically)
git flow feature finish user-dashboard
# Start a release
git flow release start 1.2.0
git flow release finish 1.2.0
3. Trunk-Based Development — For CI/CD
Everyone commits small, frequent changes directly to main (or via very short-lived
branches). Feature flags control what's visible to users. This is what Google, Facebook, and
most high-velocity teams use.
# Short-lived branch (lives < 1 day)
git checkout -b fix/typo-in-header
git commit -m "fix: correct spelling in nav header"
git push && gh pr create --fill
# PR merged same day — branch deleted
git commit --amend and
interactive rebase (git rebase -i HEAD~3) to clean up your commit history before
merging. A clean history makes debugging much easier.
Writing Great Commit Messages
Follow the Conventional Commits spec:
# Format: type(scope): description
feat(auth): add OAuth2 Google login
fix(api): handle null response from payment gateway
docs(readme): update installation instructions
refactor(db): extract query builder into separate class
test(users): add unit tests for registration flow
Pro Tips
- Use
git stashto temporarily save work without committing - Set up
.gitignorebefore your first commit — never version.envfiles - Use
git log --oneline --graph --allto visualize your branch history - Configure Git aliases:
git config --global alias.st status - Sign your commits with GPG for verified identity on GitHub