By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
(Git Flow, GitHub Flow, and Real-World Workflows)
Branch management is how you organize work in Git/GitHub without stepping on teammates’ toes, breaking production, or losing track of changes. Think of it like a construction site: - Main branch (main/master) = The finished building (production-ready code).- Feature branches = Scaffolding where workers (developers) build new rooms (features).- Release branches = Final inspections before moving in (QA/staging).- Hotfix branches = Emergency repairs (critical bug fixes).
main
master
Why it matters in production:- Without a branching strategy, teams merge chaos into main, breaking deployments, overwriting work, or deploying unfinished features.- With a strategy, you: - Deploy multiple features in parallel without conflicts. - Roll back bad changes instantly. - Isolate experiments (e.g., a risky refactor) without affecting others. - Automate CI/CD (e.g., GitHub Actions) to run tests only on relevant branches.
Real-world scenario:You’re a DevOps engineer at a SaaS company. A critical bug is reported in production. Without a branching strategy: - You’d have to dig through main to find the bug, risking more breakage.- New features in progress might accidentally get deployed.- Rollbacks would be manual and error-prone.
With Git Flow or GitHub Flow: - You create a hotfix branch from main, fix the bug, and merge it back without touching in-progress features.- CI/CD pipelines automatically deploy the fix to production.
feature/user-auth
feature/
bugfix/
docs/
release/1.2.0
hotfix/500-error
develop
feature/login
feature
release
hotfix
git --version
git init my-project
Git Flow is a set of Git extensions (not built into Git). Install it:
# macOS (Homebrew) brew install git-flow-avh # Linux (Debian/Ubuntu) sudo apt-get install git-flow # Windows (Git Bash) git clone https://github.com/petervanderdoes/gitflow-avh.git cd gitflow-avh make install
Initialize Git Flow in your repo:
git flow init
You’ll be prompted to set branch names. Use defaults (press Enter for all):
Branch name for production releases: [main] Branch name for "next release" development: [develop] Feature branches? [feature/] Bugfix branches? [bugfix/] Release branches? [release/] Hotfix branches? [hotfix/] Support branches? [support/] Version tag prefix? []
Verify:
git branch
You should see:
* develop main
Start a new feature (e.g., "user-login"):
git flow feature start user-login
This creates and checks out feature/user-login.
feature/user-login
Make changes:
echo "function login() { ... }" > auth.js git add auth.js git commit -m "Add login function"
Finish the feature (merges to develop):
git flow feature finish user-login
This: 1. Merges feature/user-login into develop.2. Deletes the feature branch.3. Checks out develop.
When develop is ready for QA, create a release:
git flow release start 1.0.0
This creates release/1.0.0 from develop.
release/1.0.0
Test and fix bugs:
echo "Fix login bug" >> auth.js git add auth.js git commit -m "Fix login bug"
Finish the release (merges to main and develop):
git flow release finish 1.0.0
This: 1. Merges release/1.0.0 into main.2. Tags main with 1.0.0.3. Merges back into develop.4. Deletes the release branch.
1.0.0
A critical bug is found in production (main). Create a hotfix:
git flow hotfix start 1.0.1
This creates hotfix/1.0.1 from main.
hotfix/1.0.1
Fix the bug:
echo "Fix critical auth bug" >> auth.js git add auth.js git commit -m "Fix critical auth bug"
Finish the hotfix (merges to main and develop):
git flow hotfix finish 1.0.1
This: 1. Merges hotfix/1.0.1 into main.2. Tags main with 1.0.1.3. Merges back into develop.4. Deletes the hotfix branch.
1.0.1
Push all branches and tags:
git push origin main develop --tags git push origin feature/* release/* hotfix/*
git commit -S
git fetch
bash git branch --merged | grep -v "\*\|main\|develop" | xargs git branch -d
git clone --depth 1
feature/short-description
bugfix/short-description
bugfix/login-error
docs/short-description
docs/api-guide
.gitignore
git tag -a v1.0.0 -m "Release 1.0.0"
bash git for-each-ref --sort=committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'
git rebase develop
git merge
git cherry-pick
git push --force
--force-with-lease
Trap: Git Flow is overkill for continuous deployment.
"How do you fix a critical bug in production using Git Flow?"
Trap: Don’t branch from develop—hotfixes must come from main.
"What’s the difference between git merge and git rebase?"
git rebase
merge
rebase
Trap: Rebasing shared branches can break others’ work.
"How do you enforce code reviews before merging to main?"
Challenge:You’re working on a team using Git Flow. A teammate accidentally merged a broken feature into develop. How do you: 1. Revert the bad merge without losing other work? 2. Ensure the fix is applied to both develop and the next release?
Solution:
# 1. Find the bad merge commit (use `git log --oneline --graph`) git revert <bad-merge-commit-hash> # Reverts the merge commit # 2. Create a hotfix branch from main (if the bug is in production) git flow hotfix start fix-broken-feature # Fix the bug, commit, then: git flow hotfix finish fix-broken-feature
Why it works:- git revert undoes the merge without rewriting history.- Hotfix ensures the fix propagates to both main and develop.
git revert
git flow feature start <name>
git flow feature finish <name>
git flow release start <version>
git flow release finish <version>
git flow hotfix start <version>
git flow hotfix finish <version>
git rebase <branch>
<branch>
git merge --no-ff <branch>
git push origin --delete <branch>
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.