Skip to main content
Glossary

Branch

A parallel version of a repository that allows developers to work on features or fixes independently without affecting the main codebase.

Detailed Explanation

Branching is Git's most powerful feature. A branch creates an independent line of development where changes can be made without affecting other branches. The main branch (usually called `main` or `master`) represents the production-ready code. Feature branches, bugfix branches, and release branches enable parallel development.

When a branch is ready, it is merged back into the target branch through a pull request or merge request. This workflow enables code review, testing, and quality assurance before changes reach production. Short-lived branches (a few hours or days) are preferred over long-lived branches to minimize merge conflicts.

Why It Matters

Branching enables safe parallel development, code review, and experimentation without risking the stability of the main codebase.

Real-World Example

A developer creates a `feature/user-auth` branch, implements login and signup, opens a pull request, gets code review approval, and merges it to `main`. Meanwhile, another developer works on `feature/payment-integration` independently.

When to Use

For any change that is not trivial. Create a branch for features, bug fixes, experiments, and even documentation updates. The cost of creating a branch in Git is nearly zero.

Advantages

  • Isolates changes from the main branch
  • Enables parallel development
  • Supports code review workflows
  • Allows experimentation without risk
  • Cheap and fast to create and merge

Disadvantages

  • Long-lived branches accumulate merge conflicts
  • Too many branches create confusion
  • Branch naming requires conventions
  • Requires discipline to delete merged branches
  • Complex merge scenarios can lose changes

Frequently Asked Questions

How long should a branch live?

As short as possible—ideally hours or days. Long-lived branches accumulate merge conflicts and become harder to merge. Trunk-based development encourages very short-lived branches or direct commits to main.

What is the main branch?

The main branch (historically called master) is the default branch representing the production-ready codebase. All other branches are compared against and merged into main.

How do I name branches?

Use descriptive prefixes: feature/user-auth, bugfix/login-error, hotfix/security-patch, docs/api-guide, refactor/db-layer. This makes it clear what type of change the branch contains.

What is a feature flag?

A feature flag lets you merge incomplete features to main while keeping them hidden from users. This avoids long-lived branches by enabling gradual rollout. LaunchDarkly and Unleash are popular feature flag services.

Should I delete branches after merging?

Yes. Delete merged branches to keep the repository clean. Most platforms (GitHub, GitLab) offer automatic branch deletion after merge. Set this as the default for your repository.

Back to Glossary

Browse all terms in our software development glossary.

Browse All Terms