Skip to content

Latest commit

 

History

History
183 lines (131 loc) · 5.4 KB

3. Gitflow Workflow.md

File metadata and controls

183 lines (131 loc) · 5.4 KB

Gitflow Workflow

The Gitflow Workflow is a structured branching model designed to streamline collaboration and simplify the development process for large teams and complex projects. This page provides an overview of Gitflow, its key components, and how to implement it.


1. What is Gitflow Workflow?

Gitflow is a Git-based workflow introduced by Vincent Driessen. It defines a strict branching model with dedicated branches for:

  • Development
  • Releases
  • Hotfixes

This model is ideal for projects with regular updates and long-term development cycles.


2. Key Concepts

Branch Types

Gitflow uses six main branch types:

  1. main:

    • The stable branch representing production-ready code.
    • Only updated through merges from release or hotfix branches.
  2. develop:

    • Contains the latest changes for the next release.
    • Serves as the integration branch for feature branches.
  3. Feature Branches:

    • Used for developing specific features.
    • Created from develop and merged back into develop.
  4. Release Branches:

    • Used to prepare for a new release.
    • Created from develop and merged into both main and develop.
  5. Hotfix Branches:

    • Used to address critical issues in production.
    • Created from main and merged back into both main and develop.
  6. Support Branches (optional):

    • Used for maintaining legacy versions of the software.

3. How Gitflow Works

Step 1: Set Up Gitflow

Initialize Gitflow in your repository:

git flow init

You’ll be prompted to confirm the names for the default branches (main and develop) and prefixes for feature, release, and hotfix branches.


Step 2: Start a Feature

Create a feature branch to develop a new feature:

git flow feature start feature-name

When the feature is complete, finish and merge it into develop:

git flow feature finish feature-name

Step 3: Start a Release

Create a release branch to prepare for the next version:

git flow release start version-number

Perform final testing, update version numbers, and finish the release. This merges the release into both main and develop:

git flow release finish version-number

Step 4: Handle Hotfixes

Create a hotfix branch to fix an urgent issue in production:

git flow hotfix start hotfix-name

After resolving the issue, finish the hotfix. This merges it into both main and develop:

git flow hotfix finish hotfix-name

4. Advantages of Gitflow

  • Organized Workflow: Clearly separates different stages of development.
  • Parallel Development: Supports multiple features and hotfixes simultaneously.
  • Stable main Branch: Ensures production code is always stable.
  • Team Collaboration: Enables a structured workflow for large teams.

5. Challenges of Gitflow

  • Complexity: Involves multiple branches and merges, which may be overwhelming for small teams or simple projects.
  • Overhead: Not suitable for projects with rapid deployment cycles.

6. Best Practices

  • Use Descriptive Branch Names: Clearly indicate the purpose of each branch, e.g., feature/login-page or hotfix/api-error.
  • Test Thoroughly: Test features and releases before merging them into main.
  • Automate Processes: Use CI/CD tools to automate testing, merging, and deployments.

7. Common Commands

Command Description
git flow init Initialize Gitflow in the repository.
git flow feature start feature-name Start a new feature branch.
git flow feature finish feature-name Merge and delete a feature branch.
git flow release start version-number Create a new release branch.
git flow release finish version-number Finalize the release and merge it into main.
git flow hotfix start hotfix-name Create a new hotfix branch.
git flow hotfix finish hotfix-name Merge and delete the hotfix branch.

8. Example Workflow

1. Start a Feature

git flow feature start add-login

Develop the feature, commit changes, and finish it:

git flow feature finish add-login

2. Prepare a Release

git flow release start 1.0.0

Test, update version numbers, and finalize the release:

git flow release finish 1.0.0

3. Fix a Critical Bug

git flow hotfix start fix-crash

Apply the fix and finish the hotfix:

git flow hotfix finish fix-crash

9. When to Use Gitflow

Gitflow is ideal for:

  • Projects with scheduled releases.
  • Teams requiring clear separation of development stages.
  • Applications with long-term support and multiple versions.

Conclusion

The Gitflow workflow provides a well-structured approach to software development, ensuring stability in production and flexibility during development. While it may add complexity, it is highly effective for large projects with organized release cycles.


Next Steps: Rebasing