Mastering Gitflow: A Step‑by‑Step Guide to Structured Git Branching
Gitflow provides a disciplined branching model for teams, using dedicated master, develop, feature, release, and hotfix branches to manage development, releases, and maintenance, and this guide walks through its concepts, branch roles, and detailed command‑line steps with examples to implement the workflow effectively.
When adopting Git in a workplace, many workflows exist; Gitflow is a popular model that defines a strict branch structure around releases.
How Gitflow Works
It uses a central repository; developers work locally and push branches. The key difference is the branch layout.
Branches for History
Two permanent branches: master holds official release history, develop integrates ongoing features. Tags are applied on master.
Feature Development Branches
Each new feature gets its own branch created from develop; after completion it is merged back into develop, never directly into master.
Release Branches
When develop has enough features or a release date approaches, a release branch is created from develop. It is used for final testing, documentation, and bug fixes. The branch is eventually merged into both master (with a tag) and develop.
Maintenance (Hotfix) Branches
Critical bugs after a release are fixed on a branch created from master. The fix is merged into master (tagged) and also back into develop.
Step‑by‑Step Example
Assume a central repository already exists.
Create develop branch
git branch develop
git push -u origin developDevelopers create feature branches
git checkout -b feature1 develop
# edit, stage, commit
git status
git add <some-file>
git commit
git checkout develop
git merge feature1
git pushPrepare a release git checkout -b release-0.1 develop Finish the release
git checkout master
git merge release-0.1
git tag -a 0.1 -m "Initial public release"
git push --tags
git checkout develop
git merge release-0.1
git push
git branch -d release-0.1Hotfix a bug
git checkout -b issue-001 master
# fix bug, commit
git checkout master
git merge issue-001
git tag -a 0.1.1 -m "Bug fix"
git push --tags
git checkout develop
git merge issue-001
git push
git branch -d issue-001Hooks can be configured on the server to trigger automated builds when tags or master are pushed.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
