Git Branching for Beginners: What Are Branches & HEAD Really?

Hey, it's me again, Tushar.
I finally wrapped my head around what Git and GitHub are, the three areas (working → staging → commit), and the basic commands to actually use them.
This post is me journaling what I learned about branches, what HEAD really is, how to switch between them, and why actual companies live and breathe this stuff. I'll keep it simple, no fluff, just the parts that finally made sense to me.
Branches Are Just Pointers (Not Copies!)
A branch in Git is not a full copy of your code. It's super lightweight.
Think of your commit history as:
- Commit A → Commit B → Commit C
Each branch is basically a movable label (a pointer) that points to one of those commits, usually the latest one in that line of work.
When you create a new branch, Git doesn't duplicate all your files. It just makes a new pointer starting at the same commit your current branch is on.
Example:
You have
mainpointing to Commit C.You run
git branch feature-loginNow
feature-loginalso points to Commit C.Both branches share the same history up to C, zero extra space used.
Then you start working on feature-login, make Commit D → now feature-login moves forward to D, but main stays at C.
That's it. Branches are cheap and fast because they're just 40-character pointers (the commit hash) stored in a tiny file.
What is HEAD?
HEAD is Git's way of saying: "This is where you are right now."
More precisely:
HEAD is a special pointer that always points to the current commit you're working on.
Usually, HEAD points to a branch name (like
mainorfeature-login).When HEAD points to a branch, we say you're "on" that branch. Any new commit you make will move that branch forward.
You can check where HEAD is with:
git branch # shows branches, * marks current one (where HEAD is)
There's also something called "detached HEAD", when HEAD points directly to a commit hash instead of a branch. That happens if you checkout an old commit by hash. In detached mode, new commits don't move any branch, they're kind of floating until you create a branch there. For beginners, just avoid detached HEAD for now (stick to branch names).
Switching Branches (The Commands I Actually Use)
Super straightforward once you get it.
See what branches exist:
git branchCreate and switch to a new branch in one command (most common):
git checkout -b feature/add-dark-mode # shorthand for: # git branch feature/add-dark-mode # git checkout feature/add-dark-modeSwitch to an existing branch:
git checkout main # or newer : git switch main
When you switch, Git updates your working directory to match the latest commit on that branch. Any uncommitted changes might come along (or Git will stop you if there's conflict).
Quick Bonus Topics That Helped Me
Naming branches — Use descriptive names:
feature/user-auth,bugfix/payment-error-500,experiment/new-ui. Prefixes help a lot.Delete branches after merge —
git branch -d feature-done(local), and GitHub usually offers to delete remote after PR merge.git log --graph --oneline --decorate — Run this. It shows branches visually, super helpful to see where things diverged.
Pull often — Before creating a new branch or switching back to main:
git pullto stay up-to-date.
Thanks for reading, Keep committing.
