Bird
Raised Fist0
Gitdevops~7 mins

Gitflow workflow - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What is the main purpose of the develop branch in the Gitflow workflow?
easy
A. It serves as the integration branch for features before release.
B. It contains the production-ready code only.
C. It is used to fix urgent bugs directly in production.
D. It stores experimental code that is not stable.

Solution

  1. Step 1: Understand the role of the develop branch

    The develop branch is where all completed features are merged and tested together before release.
  2. Step 2: Compare with other branches

    The master branch holds production-ready code, hotfix branches fix urgent bugs, and experimental code is not part of Gitflow standard branches.
  3. Final Answer:

    It serves as the integration branch for features before release. -> Option A
  4. Quick Check:

    Develop = integration branch [OK]
Hint: Develop branch integrates features before release [OK]
Common Mistakes:
  • Confusing develop with master branch
  • Thinking develop is for hotfixes
  • Assuming develop holds only stable code
2. Which command correctly starts a new feature branch named login using Gitflow?
easy
A. git flow start feature login
B. git flow feature start login
C. git start feature login
D. git feature start login

Solution

  1. Step 1: Recall Gitflow feature start syntax

    The correct syntax to start a feature branch is git flow feature start <name>.
  2. Step 2: Check each option

    Only git flow feature start login matches the correct syntax exactly. Others have incorrect order or missing 'flow'.
  3. Final Answer:

    git flow feature start login -> Option B
  4. Quick Check:

    Feature start = git flow feature start [OK]
Hint: Use 'git flow feature start <name>' to start features [OK]
Common Mistakes:
  • Omitting 'flow' in the command
  • Swapping command word order
  • Using 'git start' instead of 'git flow feature start'
3. Given the commands below, what is the final branch after finishing a release?
git flow release start 1.0.0
git flow release finish 1.0.0
medium
A. The branch is switched to master.
B. The branch is switched to develop.
C. The branch remains on release/1.0.0.
D. The branch is switched to feature/1.0.0.

Solution

  1. Step 1: Understand what 'git flow release finish' does

    This command merges the release branch into both master and develop, tags the release, and deletes the release branch.
  2. Step 2: Identify the branch after finishing release

    After finishing, Gitflow switches to master branch by default.
  3. Final Answer:

    The branch is switched to master. -> Option A
  4. Quick Check:

    Release finish switches to master [OK]
Hint: Release finish merges and switches to master [OK]
Common Mistakes:
  • Assuming branch stays on release
  • Thinking it switches to develop
  • Confusing feature branches with release
4. You ran git flow feature finish login but your changes are not in develop. What is the likely problem?
medium
A. You forgot to push the develop branch after finishing the feature.
B. You did not commit changes before finishing the feature.
C. You started the feature branch from master instead of develop.
D. You finished the feature on the master branch.

Solution

  1. Step 1: Recall feature branch base in Gitflow

    Feature branches should start from develop to ensure changes merge back there.
  2. Step 2: Analyze why changes are missing in develop

    If the feature branch was started from master, finishing it merges changes into master, not develop, causing missing updates in develop.
  3. Final Answer:

    You started the feature branch from master instead of develop. -> Option C
  4. Quick Check:

    Feature base must be develop [OK]
Hint: Feature branches must start from develop [OK]
Common Mistakes:
  • Assuming finishing auto-pushes changes
  • Not committing before finishing
  • Confusing master and develop as base
5. Your team wants to prepare a hotfix for a critical bug in production while a release is in progress. According to Gitflow, which sequence of commands correctly handles this situation?
hard
A. git flow hotfix start fix-bug; git flow release finish; git flow hotfix finish fix-bug
B. git flow release finish; git flow hotfix start fix-bug; git flow hotfix finish fix-bug
C. git flow feature start fix-bug; git flow feature finish fix-bug
D. git flow hotfix start fix-bug; git flow hotfix finish fix-bug

Solution

  1. Step 1: Understand hotfix purpose in Gitflow

    Hotfix branches are created from master to quickly fix production bugs, independent of ongoing releases.
  2. Step 2: Check command sequence for hotfix

    Starting and finishing a hotfix with git flow hotfix start and git flow hotfix finish is the correct way, regardless of release status.
  3. Step 3: Evaluate options

    git flow hotfix start fix-bug; git flow hotfix finish fix-bug correctly starts and finishes the hotfix. git flow release finish; git flow hotfix start fix-bug; git flow hotfix finish fix-bug delays hotfix until release finishes, which is not required. git flow feature start fix-bug; git flow feature finish fix-bug uses feature instead of hotfix. git flow hotfix start fix-bug; git flow release finish; git flow hotfix finish fix-bug incorrectly mixes release finish before hotfix finish.
  4. Final Answer:

    git flow hotfix start fix-bug; git flow hotfix finish fix-bug -> Option D
  5. Quick Check:

    Hotfix runs independently during release [OK]
Hint: Hotfix branches start and finish independently from release [OK]
Common Mistakes:
  • Waiting for release to finish before hotfix
  • Using feature branch for hotfix
  • Finishing release before hotfix finish