# What is a Branch?

> A lightweight, movable pointer to a specific commit, allowing parallel development.

Subject: Version Control | Lesson 8 of 29 | 4 min read
Interactive lesson: https://codewithanimation.in/git/what-is-a-branch
Previous: [Ignoring Files](https://codewithanimation.in/git/gitignore.md) | Next: [Creating & Switching Branches](https://codewithanimation.in/git/git-branch-and-switch.md)

## A Branch is Just a Pointer

A branch in Git is simply a lightweight, movable pointer to one of your commits. Unlike older version control systems, a branch is not a physical copy of your files.

It's just a small file containing the 40-character checksum of the commit it points to.

## Why it matters

Branches provide a safe, isolated sandbox. You can work on a new feature, fix a bug, or experiment with code without any risk of breaking the `main` production codebase.

Because they are just pointers, branching and switching branches in Git is nearly instantaneous.

## How it works

Git maintains a special pointer called `HEAD` that determines which branch is currently active.

When you make a new commit, Git automatically moves the active branch pointer forward to point to your new commit.

## Common mistake: The Fear of Branching

The biggest misconception is thinking branches are physical copies of directories. Because creating branches in older systems meant duplicating folders (which was slow and heavy), developers often fear branching.

In Git, creating a branch takes almost zero space and time.

## Tip: The Sticky Note Analogy

Imagine your commit history is a timeline of scrapbook pages. A branch is just a named sticky note (like 'main') stuck onto one of those pages.

When you add a new page, you just peel the sticky note off the old page and stick it onto the new one. `HEAD` is an arrow pointing at the sticky note you are currently reading.

## Try it: Follow a branch pointer

Switch between branches and create a sample commit to see which pointer advances.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/git/what-is-a-branch

## Check yourself

### Question 1

What is a Git branch fundamentally?

- A. A physical copy of all your files in a new directory.
- B. A backup copy of your repository.
- C. A lightweight, movable pointer to a specific commit.
- D. A special type of commit.

Correct answer: C

Under the hood, Git branches are simply small files containing the 40-character hash of the commit they point to.

- Why not A: Git doesn't duplicate your files into new folders for branches.
- Why not B: Branches are used for parallel development, not backups.
- Why not D: A branch is a pointer TO a commit, not a commit itself.

### Question 2

What is the purpose of the `HEAD` pointer in Git?

- A. It points to the very first commit in your repository.
- B. It is the name of the default branch.
- C. It lists all the branches in your project.
- D. It indicates the currently active local branch or commit.

Correct answer: D

Git uses the `HEAD` pointer to know what you currently have checked out. When you switch branches, HEAD moves to point to the new branch.

- Why not A: HEAD points to your current active location.
- Why not B: `main` or `master` is usually the default branch name.
- Why not C: HEAD only points to one specific branch or commit.

### Question 3

What happens to your current branch pointer when you make a new commit?

- A. The branch pointer automatically moves forward to point to the newly created commit.
- B. The branch pointer stays where it is, and a new branch is created.
- C. The branch pointer is temporarily deleted until you push.
- D. The branch pointer moves backward to the previous commit.

Correct answer: A

As you work and make commits, the branch pointer you are currently on automatically shifts forward to the new snapshot.

- Why not B: Git doesn't automatically create new branches when you commit.
- Why not C: Deleting the pointer would cause you to lose your branch reference!
- Why not D: Branch pointers move forward to encompass your new work.

## Remember this

- A branch is just a lightweight pointer to a commit.
- HEAD points to your current active branch.
- Making a commit automatically moves the active branch pointer forward.
