Git Branching Mechanics: Pointers, HEAD, and git branch0%

Git Branching Mechanics: Pointers, HEAD, and git branch

Beginner12 min read•Updated: Jul 11, 2026
Study MaterialsCheatsheet

Git Branching Mechanics: Pointers, HEAD, and git branch

Branching is Git's superpower. While older version control systems treated branches as slow, expensive filesystem copies, Git implements branches as ultra-lightweight, movable 41-byte pointers to commits. Creating, switching, and deleting branches in Git takes less than a millisecond.


1. What is a Git Branch Under the Hood?

In Git, a commit is a node in a Directed Acyclic Graph (DAG) pointing back to its parent commit.

A branch is simply an ordinary text file in .git/refs/heads/<branch-name> containing the 40-character SHA-1 hash of the most recent commit on that line of development:

Output
Commit Graph:
(Commit C1) <--- (Commit C2) <--- (Commit C3)
^
|
[main] <--- 41-byte pointer!

When you make a new commit on main, Git does not copy your project:

  1. 1
    It creates the new commit object C4 whose parent is C3.
  2. 2
    It automatically updates the [main] pointer file to point to C4!

2. The Role of the HEAD Pointer

If you have multiple branches (main, feature-login, hotfix), how does Git know which branch you are currently working on? Git maintains a special pointer called HEAD:

  • HEAD is a pointer to the current local branch you have checked out.
  • Under the hood, the file .git/HEAD contains: ref: refs/heads/main.
Output
(Commit C1) <--- (Commit C2) <--- (Commit C3)
^
|
[main]
^
|
[HEAD]

When you create a new branch called dev, Git simply creates a second pointer pointing to the exact same commit:

Output
(Commit C1) <--- (Commit C2) <--- (Commit C3)
^
/ \
[main] [dev]
^
|
[HEAD]

3. Working with git branch

A. List Local Branches

Bash / Terminal
git branch

The asterisk * and green highlight indicates the active branch pointed to by HEAD:

Output
* main
feature-auth
bugfix-navbar

B. List Remote and Local Branches

Bash / Terminal
git branch -a

C. Create a New Branch (Without Switching)

Bash / Terminal
git branch feature-payment

D. Delete a Branch Safely

Once a feature branch is merged into main, clean it up:

Bash / Terminal
# Deletes branch ONLY if it has been fully merged
git branch -d feature-payment

E. Force Delete an Unmerged Branch

If you abandoned a spike or prototype that was never merged:

Bash / Terminal
# Force delete unmerged branch
git branch -D spike-prototype

F. Rename the Current Branch

Bash / Terminal
git branch -m new-branch-name

4. Why Branching Transforms Team Engineering

  • Zero-Risk Isolation: You can experiment, break things, and try wild architectural changes without risking production stability.
  • Concurrent Feature Development: 50 engineers can develop 50 separate features simultaneously on isolated branches without stepping on each other's code.
  • Short-Lived Feature Branches: Industry standard engineering creates a branch for a single ticket, completes it in 1–2 days, opens a Pull Request, merges it, and deletes the branch.

Interactive Quiz

Practice Quiz

Question 1
What is a Git branch physically stored as inside the .git directory?
Question 2
What does the special Git pointer HEAD refer to?
Question 3
What command creates a new branch named feature-cart without automatically switching to it?
Question 4
What is the difference between git branch -d and git branch -D?
Question 5
In git branch output, what indicates the currently checked-out branch?
Next Lesson

Switching Branches with git switch and git checkout -b

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext