Course contentsShow
← Software Engineering
Lesson 55 of 1,9332. Version Control with GitFree lesson

Understanding Git Branches

Learn what branches are in Git, how they represent independent lines of development, and why they're lightweight.

Understanding Git Branches

What you'll learn: You'll discover what branches are in Git and why they're one of its most powerful features for managing different lines of work.

What Are Branches?

Think of a Git branch as a parallel universe for your code. When you create a branch, you're making an independent line of development where you can experiment, add features, or fix bugs without affecting your main codebase.

In practical terms, a branch is simply a movable pointer to a specific commit. Every repository starts with one default branch (usually called main or master). This branch points to your latest commit. When you create a new branch, Git creates another pointer that you can move independently.

Why Branches Are Lightweight

Unlike some older version control systems that copy entire directories, Git branches are incredibly efficient. Creating a branch in Git only creates a 41-byte file containing a reference to a commit hash—that's it! No copying files, no duplication of your entire codebase.

This means you can:

  • Create branches instantly
  • Switch between branches quickly
  • Maintain dozens or hundreds of branches without performance issues

Independent Lines of Development

Each branch lets you work on something different simultaneously. You might have:

  • A main branch with stable, production-ready code
  • A feature-login branch where you're building authentication
  • A bugfix-typo branch fixing a small error

These branches exist side-by-side. Changes in one don't affect the others—until you deliberately merge them together (which you'll learn about soon).

Key Takeaway: Git branches are lightweight pointers to commits that enable independent, parallel lines of development without duplicating your codebase.