Git Branches Don't Contain Commits, They Point To Them

❌ Branches contain commits ✅ Branches just point to commits 🧠 What We Expect Most of us think: 👉 Each branch has its own commits 👉 Feature branches store separate histories 👉 Same starting commit is duplicated across branches In short: ❌ “Branches contain commits” 🔍 How Git Actually Works Git doesn’t store commits inside branches. Instead, everything lives in a Directed Acyclic Graph (DAG) 👉 A connected structure where: ⬢ Each commit points to its parent commit ⬢ History flows backward ⬢ No duplication, only relationships 🌿 What Happens in the Diagram ⬢ All commits are connected via parent relationships (PCH) ⬢ Both branches start from a common base commit (shared, not copied) ⬢ The history diverges into two paths ⬢ Each branch adds new commits on its own path 🎯 Branches & HEAD (The Most Misunderstood Part) 👉 A branch is just a pointer (label): feature-branch-1 → latest commit (blue) feature-branch-2 → latest commit (yellow) 👉 HEAD is another pointer: HEAD → current branch → commit ✔ Only one HEAD exists at a time ✔ It defines your current working position 🚀 Key Insights 1️⃣ git log moves backward using parent links From current commit: blue → orange → pink 👉 Git follows Parent Commit Hash (PCH) step by step 2️⃣ No duplicate commits across branches 👉 Both branches share the same base commit ✔ Stored once ✔ Referenced multiple times 3️⃣ Commits are globally accessible git log <commit-hash> 👉 Works from any branch ✔ Because commits belong to the graph, not a branch 4️⃣ Deleting a branch doesn’t delete commits 👉 Only the pointer is removed ✔ Commits remain in the graph ✔ Removed later by garbage collection 5️⃣ Branches are just pointers 👉 They don’t store commits 👉 They only point to the latest commit 6️⃣ Divergence = new commits, not copies From a common base: One path → green → yellow Another path → orange → blue ✔ New commits are created ❌ Old commits are never duplicated 💡 Core Idea Commits = nodes Branches = pointers (labels) HEAD = current pointer 🔥 Once this clicks, Git becomes predictable. #Git #DevOps #SoftwareEngineering #VersionControl #Backend #TechConcepts #CodeNewbie #TechEducation #CodingLife #DevCommunity #SystemDesign #SoftwareDevelopment #TechLearning

  • diagram

To view or add a comment, sign in

Explore content categories