Day 07/13 of Git 101 Series
Branches as Pointers
Concept Explanation
A Git branch is simply a pointer to a specific commit.
No file copies. No extra directory. No magic duplication.
When you create a new commit, the branch pointer moves forward to that commit.
HEAD is a symbolic reference telling Git which branch you're currently on.
If HEAD points to refs/heads/main, your commits will advance main.
If it points to refs/heads/feature-x, your commits advance feature-x.
Commands
List branches
git branch
Create a branch
git branch feature-login
Switch to a branch
git switch feature-login
Create and switch in one go
git switch -c feature-login
Delete a branch
git branch -d feature-login
Older alternative
git checkout feature-login
Example
You are on main and want isolated work:
git switch -c login-ui
Make changes and commit:
git add .
git commit -m "add login ui"
Now the login-ui pointer moves forward while main stays at its previous commit.
Merge when you're done:
git switch main
git merge login-ui
Clean up:
git branch -d login-ui
Real-World Use Case
Teams often work on multiple features at the same time.
Each feature, bug fix, or experiment gets its own branch to avoid breaking main.
Common structure:
- main or master
- feature-x
- hotfix-y
- experiment-z
Branches isolate work, reduce conflicts, and let developers test changes safely.
Under-the-Hood Explanation
Branches are stored as simple text files inside .git/refs/heads/.
Examples:
.git/refs/heads/main
.git/refs/heads/login-ui
Each file contains exactly one thing: a commit hash.
Example content:
a97b23c98e1f94af1df8a908d50ae1f7203d36f1
HEAD lives at:
.git/HEAD
Typical content:
ref: refs/heads/main
This means HEAD points to the branch, not directly to a commit.
When you commit, Git:
- Creates a new commit object
- Rewrites the branch file with the new commit hash
- HEAD follows automatically because it references the branch
No file duplication. No directory cloning.
Just lightweight pointers walking through the commit graph.