MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Git Branching Mechanics: Pointers, HEAD, and git branch0%
Study Materials
Git & GitHub BasicsProgress 0%
1.1What is Version Control? (Local, Centralized vs Distributed VCS)1.2Why Git? History, Architecture & Core Benefits1.3The Three Trees: Working Directory, Staging Area & Git Repository1.4Installing Git and Initial Configuration (git config user.name / email)
4.1Git Branching Mechanics: Pointers, HEAD, and git branch4.2Switching Branches with git switch and git checkout -b4.3Merging Branches: Fast-Forward vs Three-Way Merges (git merge)4.4Resolving Merge Conflicts Step-by-Step with Conflict Markers
HomeTutorialsGit & GitHub BasicsGit Branching Mechanics: Pointers, HEAD, and git branch
Switching Branches with git switch and git checkout -b

Git Branching Mechanics: Pointers, HEAD, and git branch

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

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:

1Commit Graph:
2(Commit C1) <--- (Commit C2) <--- (Commit C3)
3 ^
4 |
5 [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.
1 (Commit C1) <--- (Commit C2) <--- (Commit C3)
2 ^
3 |
4 [main]
5 ^
6 |
7 [HEAD]

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

1 (Commit C1) <--- (Commit C2) <--- (Commit C3)
2 ^
3 / \
4 [main] [dev]
5 ^
6 |
7 [HEAD]

3. Working with git branch

A. List Local Branches

1git branch

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

1* main
2 feature-auth
3 bugfix-navbar

B. List Remote and Local Branches

1git branch -a

C. Create a New Branch (Without Switching)

1git branch feature-payment

D. Delete a Branch Safely

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

1# Deletes branch ONLY if it has been fully merged
2git branch -d feature-payment

E. Force Delete an Unmerged Branch

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

1# Force delete unmerged branch
2git branch -D spike-prototype

F. Rename the Current Branch

1git 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• Knowledge Check

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.

Related Lessons

Previous LessonNext Lesson
Ignoring Unwanted Files and Secrets using .gitignore RulesSwitching Branches with git switch and git checkout -b

Practice Quiz

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

Mentor-Led Practical Training

Master Git & GitHub Basics with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext