0
0
Gitdevops~7 mins

Gitflow workflow - Commands & Configuration

Choose your learning style9 modes available
Introduction
Gitflow workflow helps teams organize their work by using branches for features, releases, and fixes. It solves the problem of managing multiple changes safely without mixing unfinished work with stable code.
When you want to develop new features without affecting the main code.
When you need to prepare a release version with testing and fixes.
When you want to quickly fix bugs in the production code without disrupting ongoing work.
When multiple developers work on different parts of the project simultaneously.
When you want a clear history of what changes were made for features, releases, and fixes.
Commands
Create and switch to the 'develop' branch from 'main' to start development work separately from the stable main branch.
Terminal
git checkout -b develop main
Expected OutputExpected
Switched to a new branch 'develop'
-b - Create a new branch and switch to it
Create and switch to a new feature branch 'feature/login' from 'develop' to work on a login feature without affecting other code.
Terminal
git checkout -b feature/login develop
Expected OutputExpected
Switched to a new branch 'feature/login'
-b - Create a new branch and switch to it
Stage all changed files in the current directory to prepare them for committing.
Terminal
git add .
Expected OutputExpected
No output (command runs silently)
Save the staged changes with a clear message describing the login feature work.
Terminal
git commit -m "Add login feature implementation"
Expected OutputExpected
[feature/login abc1234] Add login feature implementation 3 files changed, 45 insertions(+), 2 deletions(-)
-m - Add a commit message inline
Switch back to the 'develop' branch to prepare for merging the finished feature.
Terminal
git checkout develop
Expected OutputExpected
Switched to branch 'develop'
Merge the completed login feature branch into 'develop' to include the new feature in the development code.
Terminal
git merge feature/login
Expected OutputExpected
Updating def5678..abc1234 Fast-forward login.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
Switch to the 'main' branch to prepare for a release.
Terminal
git checkout main
Expected OutputExpected
Switched to branch 'main'
Merge the 'develop' branch into 'main' to release the latest stable code.
Terminal
git merge develop
Expected OutputExpected
Updating def5678..abc1234 Fast-forward app.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
Create a tag named 'v1.0' on the current commit to mark the release version.
Terminal
git tag -a v1.0 -m "Release version 1.0"
Expected OutputExpected
No output (command runs silently)
-a - Create an annotated tag
-m - Add a message to the tag
Key Concept

If you remember nothing else from this pattern, remember: use separate branches for features, development, and releases to keep work organized and stable.

Common Mistakes
Committing directly to the main branch without using feature or develop branches
This mixes unfinished or unstable code with the stable production code, causing bugs or downtime.
Always create and work on feature branches, then merge into develop and main branches following Gitflow.
Merging feature branches directly into main instead of develop
It bypasses the testing and integration phase in develop, risking unstable code in production.
Merge feature branches into develop first, then merge develop into main for releases.
Not tagging releases after merging into main
Without tags, it's hard to identify or roll back to specific release versions.
Create annotated tags on main after each release merge to mark versions clearly.
Summary
Create a 'develop' branch from 'main' to separate development from stable code.
Use feature branches from 'develop' to work on new features safely.
Merge feature branches back into 'develop' when done, then merge 'develop' into 'main' for releases.
Tag releases on 'main' to mark stable versions clearly.