← Back to list

Git Branching & Merging Branching Strategies Explained

A simple guide to how development teams safely build, manage, and release code using Git

Amirdhagadesan Rajasekar · 2026-05-26 05:16 · 0 claps · 2.6 min read
#git-branching #branching-strategy #git-branching-strategy #git-merge #merging-strategy
Open on Medium ↗

Git Branching & Merging Branching Strategies Explained

A simple guide to how development teams safely build, manage, and release code using Git

Git Branching & Merging Explained: A Simple Guide with Real Examples

Git Branching & Merging Explained: A Simple Guide with Real Examples

Introduction

When multiple developers work on the same code base, things can quickly become messy without structure.

That’s where branching and merging strategies come in.

They help teams:

  • Work independently without breaking each other’s code
  • Manage features, fixes, and releases smoothly
  • Maintain a clean and stable code base

In this guide, you’ll learn everything in a practical and simple way.

What is Branching Strategy?

A branching strategy defines:

How developers create, use, and manage branches in a repository

  • Ensures structured development
  • Provides rules for writing and integrating code
  • Reduces merge conflicts
  • Improves collaboration

Why Branching Strategy is Important?

  • Multiple developers can work at the same time
  • Code changes are isolated and safe
  • Releases are controlled and stable
  • Bugs can be fixed without disturbing others

Common Branching Strategies

1. GitFlow (Structured Approach)

Best for: Large teams and multiple releases

Branches:

  • main → Production
  • develop → Integration
  • feature → New work
  • release → Release preparation
  • hotfix → Urgent fixes
main ---------●-------●---------
             /         \
develop ----●---●-------●---●-------
           /   /         \
feature --●---●   release ●

2. GitHub Flow (Simple and Fast)

Best for: Continuous delivery

  • Only main + feature branches
  • Short-lived branches
main --------●---------●-------
              \       /
feature -------●-----●

3. GitLab Flow

Best for: Balanced CI/CD environments

  • Combines structure + flexibility

4. Trunk-Based Development

Best for: Mature DevOps teams

  • Single main branch
  • Frequent commits
  • Feature flags
main -----●--●--●--●--●----
         /   /    /
feature ●---●----●

Step-by-Step: Branching Commands (Practical Guide)

Let’s walk through a real-world scenario using your repo:

👉 https://github.com/Amirdhagadesan/branchingGitFlow/tree/main

  1. Clone the Repository
git clone https://github.com/Amirdhagadesan/branchingGitFlow.git
cd branchingGitFlow

2. Check Current Branch

git branch

3. Create a New Feature Branch

This creates and switches to a new branch.

git checkout -b feature/user-login

4. Verify Branch

git branch

5. Make Changes

Example:

  • Add new files
  • Update code

6. Add and Commit Changes

git add .
git commit -m "Added user login feature"
  1. Push Branch to Remote
git push origin feature/user-login

Branching Flow Diagram

main -----------o-----------o---------
                  \
feature -----------o----o----o

What is Merging Strategy?

A merging strategy defines:

How changes from one branch are combined into another branch

In simple terms:

  • Branching = Work separately
  • Merging = Combine everything together

Step-by-Step: Merging Commands

1. Switch to Target Branch (usually main or develop)

git checkout main
  1. Pull Latest Changes
git pull origin main
  1. Merge Feature Branch
git merge feature/user-login
  1. Resolve Conflicts (if any)

If conflicts occur:

  • Open the file
  • Fix conflicts manually
  • Then run:
git add .
git commit -m "Resolved merge conflict
  1. Push Merged Code
git push origin main

6. Delete Feature Branch (optional)

git branch -d feature/user-login
git push origin --delete feature/user-login

Merging Flow Diagram

main -----o------o-------o------M
           \            /
feature ----o----o----o

Types of Merging

1. Fast-Forward Merge

  • Happens when no branching conflict
  • Linear history
git merge feature-branch

2. Three-Way Merge

  • Creates a merge commit
  • Used when branches diverge

3. Rebase (Alternative to Merge)

  • Cleaner history
  • No extra merge commits
git checkout feature/user-login
git rebase main

Best Practices (Highly Recommended)

  • Keep branches short-lived
  • Merge frequently
  • Use meaningful names (feature/payment, bugfix/login-error)
  • Always review code before merging
  • Keep main branch stable

Key Benefits

  • Safe development without breaking production
  • Faster parallel work
  • Better code quality
  • Easy debugging and rollback

Conclusion

Branching and merging strategies are the backbone of modern software development.

  • Branching allows teams to work independently
  • Merging brings everything together safely
  • Strategy ensures discipline and quality

Start simple with GitHub Flow, then adopt advanced strategies like GitFlow as your project grows.


메타데이터
post_id
53ffbbac1949
slug
git-branching-merging-branching-strategies-explained-53ffbbac1949
url
https://medium.com/@amirdhagadesan.rajasekar/git-branching-merging-branching-strategies-explained-53ffbbac1949
canonical_url
https://medium.com/@amirdhagadesan.rajasekar/git-branching-merging-branching-strategies-explained-53ffbbac1949
author_url
https://medium.com/@amirdhagadesan.rajasekar
status
ok
fetched_at
2026-08-18 14:54:50