This document outlines the GitFlow branching strategy used in the DotNetExtensions.OAuth20 project. Adhering to this workflow ensures consistent and organized code management across the project.
- Overview
- Visual Diagram
- Branch Types
- Quick Reference Guide
- Branch Naming Conventions
- Protected Branch Policies
- Workflow Steps
- Common Pitfalls and How to Avoid Them
- References
GitFlow is a branching model that provides a robust framework for managing larger projects. It defines a strict branching model designed around the project release. This document explains how we implement GitFlow in the DotNetExtensions.OAuth20 project.
Figure 1: GitFlow Branching Model (taken from Atlassian GitFlow Workflow)
- Branch Name:
main
- Purpose: Contains production-ready code.
- Protected: Yes
- Branch Name:
develop
- Purpose: Integrates features for the upcoming release.
- Protected: Yes
- Prefix:
feature/
- Purpose: Used to develop new features for the upcoming release.
- Base Branch:
develop
- Prefix:
bugfix/
- Purpose: Used to fix non-critical bugs identified during the current release cycle.
- Base Branch:
develop
- Prefix:
hotfix/
- Purpose: Used to fix critical issues in the production code.
- Base Branch:
main
- Prefix:
release/
- Purpose: Prepare for a new production release.
- Base Branch:
develop
Branch Type | Prefix | Base Branch | Merge Into | Purpose |
---|---|---|---|---|
Main | main |
N/A | N/A | Production-ready code |
Develop | develop |
main |
N/A | Integration of features |
Feature | feature/ |
develop |
develop |
New feature development |
Bugfix | bugfix/ |
develop |
develop |
Non-critical bug fixes |
Hotfix | hotfix/ |
main |
main , develop |
Critical fixes in production |
Release | release/ |
develop |
develop , main |
Release preparation |
-
Feature Branches:
git checkout -b feature/feature-name develop
-
Bugfix Branches:
git checkout -b bugfix/bugfix-name develop
-
Hotfix Branches:
git checkout -b hotfix/hotfix-name main
-
Release Branches:
git checkout -b release/version-number develop
Branch names should be descriptive and use lowercase letters with hyphens to separate words.
The following branches are protected to prevent direct pushes and require pull requests for merging:
main
develop
Protection Rules:
- Pull Request Reviews: At least one approval is required.
- Status Checks: All CI checks must pass before merging.
- No Force Pushes: Force pushes are not allowed.
- No Deletions: Deleting these branches is prohibited.
Exceptions to these policies can only be made by project maintainers in exceptional circumstances.
-
Update
develop
Branch:git checkout develop git pull origin develop
-
Create Feature Branch:
git checkout -b feature/your-feature-name develop
-
Develop Your Feature:
- Commit changes following the commit message conventions.
-
Push Feature Branch to Remote:
git push origin feature/your-feature-name
-
Create a Pull Request:
- Target Branch:
develop
- Ensure all CI checks pass.
- Get at least one approval.
- Target Branch:
-
Merge the Pull Request:
- Use "Squash and Merge" to maintain a clean history.
-
Delete the Feature Branch:
- After merging, delete the feature branch from remote.
-
Update
main
Branch:git checkout main git pull origin main
-
Create Hotfix Branch:
git checkout -b hotfix/your-hotfix-name main
-
Fix the Issue:
- Commit changes with appropriate messages.
-
Push Hotfix Branch to Remote:
git push origin hotfix/your-hotfix-name
-
Create Pull Requests:
- Target Branches:
main
anddevelop
- Ensure all CI checks pass.
- Get necessary approvals.
- Target Branches:
-
Merge the Pull Requests:
- Merge into
main
first, then intodevelop
.
- Merge into
-
Tag the Release (if applicable):
git checkout main git pull origin main git tag -a vX.X.X -m "Release version X.X.X" git push origin vX.X.X
-
Forgetting to Pull Latest Changes:
- Issue: Conflicts may occur if you don't have the latest code.
- Solution: Always pull the latest changes before creating a new branch.
-
Incorrect Base Branch:
- Issue: Branching from the wrong base can cause integration issues.
- Solution: Verify you're on the correct base branch (
develop
ormain
) before creating a new branch.
-
Not Following Naming Conventions:
- Issue: Inconsistent branch names make tracking difficult.
- Solution: Adhere strictly to the naming conventions outlined above.
-
Directly Pushing to Protected Branches:
- Issue: This action is blocked and may cause delays.
- Solution: Always create a pull request for merging into protected branches.
By following this GitFlow workflow, we maintain a clean and organized codebase that facilitates collaboration and efficient development.