Skip to content

What Branches Are and Why They Matter

Branching is the feature that makes Git genuinely powerful for real-world development. Without branches, everyone working on a project is always editing the same line of history — every change is immediately mixed with everyone else’s. With branches, each developer works in isolation, and changes are only combined when they are ready.

Understanding what a branch actually is in Git makes everything about branching easier to reason about.

A branch is a lightweight movable pointer to a commit.

That is the whole thing. A branch is not a copy of your code. It is not a separate folder. It is a file containing a 40-character commit hash — a pointer to one specific commit in the repository.

When you create a commit on a branch, the branch pointer automatically moves forward to point at the new commit. Every new commit moves the pointer. The branch is always at the tip of the line of commits you made on it.

Initial commit → Second commit → Third commit
main (branch pointer)

When you create a new branch called feature, it starts as another pointer to the same commit:

Initial commit → Second commit → Third commit
↑ ↑
main feature

Both main and feature point at the same commit. Now if you make a commit on feature:

Initial commit → Second commit → Third commit → Feature commit
↑ ↑
main feature

main has not moved. feature has advanced. The two branches now have different histories from that split point — but they share all of the commits before it.

HEAD is a special pointer that tells Git which branch (and therefore which commit) you are currently on. When you see HEAD -> main in git log output, it means HEAD is pointing at the main branch.

When you switch branches, HEAD moves:

Terminal window
git switch feature

Now HEAD -> feature. Any new commits you make go onto feature and leave main unchanged.

Without branches, you have no safe way to work on a new feature while the current version of the site needs a bug fix. If you start building a new navigation section but the contact form breaks halfway through, you are stuck — your unfinished navigation and the broken contact form are in the same place.

With branches:

  • main always contains working, deployable code
  • Feature work happens on a feature branch: feature/new-navigation
  • A bug fix happens on its own branch: fix/contact-form-validation
  • Each branch is merged into main only when the work is complete and tested

This is the foundation of every professional Git workflow. Teams with one developer, teams with hundreds, and every open-source project in the world work this way.

Creating a branch in Git is nearly free. It creates a single file — around 40 bytes — containing the commit hash it points to. There is no copying, no duplication of files, no performance overhead. This is why Git encourages branching for everything, including tiny changes.

You do not need to create a branch yet — the next lesson covers that in detail. For now, build the mental model:

  1. Run git log --oneline in your git-practice folder. Find the hash of your most recent commit.

  2. Run git log --oneline --graph --all. Notice that HEAD and main both point to the same commit. There is currently only one branch.

  3. Read the output of git status and find the “On branch main” line. This is HEAD pointing to main.

Think about what it means that main is just a pointer to that one commit. The history did not change — the pointer just moved forward each time you committed.

  • A branch is a lightweight movable pointer to a commit — a file containing a commit hash.
  • When you commit on a branch, the branch pointer automatically moves forward to the new commit.
  • HEAD is a special pointer indicating your current position. HEAD -> main means you are on main.
  • Branches are nearly free to create — no code is copied, no files are duplicated.
  • Branches allow parallel lines of development: feature work, bug fixes, and experiments that do not affect each other until you choose to merge them.

The next lesson covers creating and switching branches — the two commands you will use dozens of times in every project.