DEV Community

Alireza Razinejad
Alireza Razinejad

Posted on

Git flow that's simple, easy to manage, and generally applicable

This Git flow ensures a structured and organized development process, making it easier to manage changes, track progress, and maintain the stability of the main codebase while incorporating a dedicated branch for QA testing.

Branching Strategy

Main Branches

  • main: This branch contains the production-ready code. Every commit to main should be a release.
  • develop: This branch contains the latest development changes. It is the integration branch for feature branches.

Supporting Branches

  • feature/*: These branches are used to develop new features. They branch off from develop and are merged back into develop once the feature is complete.
  • bugfix/*: These branches are used to fix bugs found in the develop branch. They branch off from develop and are merged back into develop once the bug is fixed.
  • release/*: These branches support the preparation of a new production release. They allow for minor bug fixes and preparing meta-data for a release (version number, build date, etc.). They branch off from develop and are merged into both develop and main.
  • hotfix/*: These branches are for critical fixes that need to be applied directly to the main branch. They branch off from main and are merged back into both main and develop.

Workflow

Feature Development

  1. Create a new feature branch from develop:

    git checkout develop
    git pull origin develop
    git checkout -b feature/your-feature-name
    
  2. Develop your feature.

  3. Once the feature is complete and tested locally, push it to the remote repository:

    git push origin feature/your-feature-name
    
  4. Create a merge request (MR) from feature/your-feature-name to develop.

Bug Fixing

  1. Create a new bugfix branch from develop:

    git checkout develop
    git pull origin develop
    git checkout -b bugfix/your-bugfix-name
    
  2. Fix the bug.

  3. Once the bug is fixed and tested locally, push it to the remote repository:

    git push origin bugfix/your-bugfix-name
    
  4. Create a merge request (MR) from bugfix/your-bugfix-name to develop.

Preparing a Release

  1. When all the features for the next release are merged into develop, create a new release branch:

    git checkout develop
    git pull origin develop
    git checkout -b release/0.0.1
    
  2. Perform final testing and bug fixing on the release/0.0.1 branch.

  3. Once the release is ready, merge it into main:

    git checkout main
    git pull origin main
    git merge release/0.0.1
    git push origin main
    
  4. Also, merge it back into develop to keep it updated:

    git checkout develop
    git pull origin develop
    git merge release/0.0.1
    git push origin develop
    
  5. Delete the release branch:

    git branch -d release/0.0.1
    git push origin --delete release/0.0.1
    

Hotfixes

  1. Create a hotfix branch from main:

    git checkout main
    git pull origin main
    git checkout -b hotfix/your-hotfix-name
    
  2. Fix the issue.

  3. Once the hotfix is complete, merge it into main:

    git checkout main
    git pull origin main
    git merge hotfix/your-hotfix-name
    git push origin main
    
  4. Also, merge it into develop to keep it updated:

    git checkout develop
    git pull origin develop
    git merge hotfix/your-hotfix-name
    git push origin develop
    
  5. Delete the hotfix branch:

    git branch -d hotfix/your-hotfix-name
    git push origin --delete hotfix/your-hotfix-name
    

Merging Rules

  • Feature/Bugfix to Develop: A feature or bugfix branch must pass code review and be tested locally before being merged into develop.
  • Release to Main: The release branch must pass final QA testing before being merged into main.
  • Hotfix to Main and Develop: Hotfix branches should be used for critical issues in the production environment and must be merged into both main and develop after fixing.

Conclusion

This Git flow provides a clear and straightforward process for managing development, testing, and releases. By using dedicated branches for features, bug fixes, QA testing, and hotfixes, it ensures code quality and stability, making it easier to track progress and maintain the main codebase.

Top comments (0)