Skip to main content

Command Palette

Search for a command to run...

Commonly used Git branching strategies in a DevOps scenario.

Published
2 min read

Scenario:

Imagine a team working on a web application. They follow a DevOps approach to ensure continuous integration and delivery.

1. Feature Branching:

Suppose a developer is tasked with adding a new feature - a user authentication system.

# Start a new feature branch
git checkout -b feature/user-auth

# Work on the feature, make commits
# ...

# Merge the feature branch back to main
git checkout main
git merge feature/user-auth

2. Release Branching:

Now, the team is ready to prepare for a new release of their application.

# Start a new release branch
git checkout -b release/1.0.0

# Perform final changes, bug fixes, update version number
# ...

# Merge the release branch into both main and master branches
git checkout main
git merge release/1.0.0
git checkout master
git merge release/1.0.0

3. Hotfix Branching:

After the release, a critical security issue is discovered in production that needs an immediate fix.

# Start a hotfix branch
git checkout -b hotfix/1.0.1

# Apply necessary fixes
# ...

# Merge the hotfix branch into both main and master branches
git checkout main
git merge hotfix/1.0.1
git checkout master
git merge hotfix/1.0.1

4. Gitflow Workflow:

The team decides to follow the Gitflow workflow for structured development.

# Start a new feature using Gitflow
git flow feature start feature-x

# Finish the feature, automatically merges into develop branch
git flow feature finish feature-x

# Start a release
git flow release start 1.1.0

# Finish the release, merges into develop and master, and tags the release
git flow release finish 1.1.0

5. GitHub Flow:

Developers collaborate on a new feature using GitHub Flow.

  • Create a new branch on GitHub.

  • Clone the repository locally.

  • Make changes, commit, and push to the branch.

  • Open a pull request on GitHub for code review.

  • Merge the pull request to merge changes into the main branch.

6. Trunk-Based Development:

The team practices Trunk-Based Development for more frequent integration.

# Regularly merge short-lived branches into the main branch
git checkout main
git merge feature/user-auth

These examples illustrate how various Git branching strategies are applied in a DevOps environment. The chosen strategy depends on the team's workflow, project requirements, and collaboration preferences. The key is to ensure smooth integration, code stability, and efficient release management.

More from this blog

Vishal Parit's Blogs

14 posts