What is a Branch

11.1 Why Branches Exist

Branches are designed to solve a key software development challenge:

How do you develop new features without breaking the stable version of the project?

By isolating work, branches allow:
• Safe experimentation
• Independent feature development
• Collaboration without stepping on each other's changes
• Testing ideas without affecting main code

11.2 How Branches Work Internally

A branch is essentially:
• A lightweight pointer to a commit.
• Stored as a simple file under .git/refs/heads/.

When you create a branch:
• Git doesn't copy your project.
• It just creates a new label pointing to the current commit.

When you make a commit on that branch:
• The branch pointer moves forward.
• Other branches remain unchanged.

This makes branching extremely fast and cheap compared to older VCS tools.

11.3 Common Branches in Real Projects

main / master
The primary, stable branch.

feature branches
Used for building new features:
feature/login-auth
feature/user-profile-ui

bugfix branches
For isolated fixes:
bugfix/password-reset

release branches
Preparing versions:
release/v2.3.0

hotfix branches
Emergency fixes on production code:
hotfix/critical-payment-failure

Branches keep your project structured and organized.

11.4 HEAD and Branch Relationship

HEAD is Git's pointer to your current branch (or commit).

When on a branch:
HEAD -> main

When you create a branch:
HEAD -> new-feature

When you commit:
new-feature moves forward
main stays where it was

Understanding HEAD is key to understanding branches.

11.5 Branches Enable Parallel Development

Branches make collaboration smooth because:
• Each developer can work in their own isolated branch.
• No conflicts until merging.
• Teams can run CI/CD pipelines for individual branches.
• Risky experiments do not affect production code.
This is one reason Git is dominant in modern workflows.

11.6 Key Takeaways

• A branch is a lightweight pointer to a commit, enabling isolated work.
• Branches allow teams to work in parallel without interfering with each other.
• Common types include feature, bugfix, release, and hotfix branches.
• Git branches are extremely fast and flexible because they are just references, not copies.
• HEAD determines which branch you're currently on and moves as you commit.