Labs ICT
Pro Login

What is Git Branching? Why It Matters

General Tools & Setup 6 min read

Branching lets you work on features without affecting main code. Learn branches, merging, and conflict resolution.

What is Git Branching? Why It Matters

Branching lets you work on features without affecting the main code. It's like creating a parallel universe where you can experiment safely.

What are Branches?

A branch is a separate line of development. The main branch is usually called main or master. When you create a branch, you get a copy of the code that you can modify independently.

Why Branching Matters

  • Isolation — Work on features without breaking main
  • Collaboration — Multiple developers work simultaneously
  • Experimentation — Try new ideas safely
  • Code review — Review changes before merging

Branch Commands

# Create a new branch
git branch feature-login

# Switch to a branch
git checkout feature-login

# Create and switch in one command
git checkout -b feature-login

# List all branches
git branch -a

# Delete a branch
git branch -d feature-login

Merging Branches

When your feature is ready, merge it back to main:

# Switch to main
git checkout main

# Merge your feature branch
git merge feature-login

Handling Merge Conflicts

Sometimes two branches change the same line. Git doesn't know which to keep:

<<<<<<< HEAD
console.log("Main branch version");
=======
console.log("Feature branch version");
>>>>>>> feature-login

Choose the correct version, remove the conflict markers, and commit:

# After fixing conflicts
git add .
git commit -m "Resolved merge conflict"

Branch Naming Conventions

  • feature/ — New features
  • bugfix/ — Bug fixes
  • hotfix/ — Urgent fixes
  • release/ — Release preparation

Note: Branching is fundamental to Git workflow. Master it early — you'll use branches in every project.