❌ 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
Git Branches Don't Contain Commits, They Point To Them
More Relevant Posts
-
Day 101. I'm back on the consistency grind. No fluff. Let's talk about something I've been sharpening — Git DAGs. You've used git commit, git reset, git revert. But do you actually know what's happening under the hood? DAG = Directed Acyclic Graph. Directed → commits point to their parent(s). Time only moves forward. Acyclic → no loops. History never circles back on itself. Graph → it's a network of nodes (commits) and edges (parent relationships). Every commit is a snapshot — not a diff, not a delta. A full picture of your entire repo at that moment, stored as a SHA hash. Now the three commands people confuse: git checkout → moves your HEAD to a different commit or branch. You're not changing history — you're just looking at a different snapshot. Like rewinding a film without cutting any frames. git reset → rewrites history. Moves the branch pointer backward. Three flavors: --soft → keeps your changes staged --mixed → keeps changes unstaged --hard → wipes everything. No mercy. git revert → the safe option. Creates a new commit that undoes a previous one. History stays intact. This is what you use on shared branches. I've done Git before. But "done" and "sharp" are two different things. I'm going deeper — understanding conflicts at the DAG level, debugging merges, knowing why a rebase breaks so I can fix it, not just panic-force-push. If you're learning Git too, stop memorizing commands. Learn the graph. Day 101. Still here. Still building. #Git #DevOps #100DaysOfCode #CloudEngineering #Infracodebase #LearningInPublic
To view or add a comment, sign in
-
-
Day 103. Branching and pull requests. Not flashy. But this is where real team Git lives. Spent today understanding branching properly — not just git checkout -b and hoping for the best, but why branches exist in the DAG. A branch is just a pointer. A lightweight label on a commit node. That's it. Then pull requests. A PR isn't a Git feature — it's a conversation. You're not just merging code, you're saying "hey, here's what I built, here's why, review it before it touches main." The discipline of: Branching off main cleanly Making focused commits Writing a PR description that actually explains the change ...that's the difference between a codebase you can navigate and one that's a nightmare. Still sharpening. Day 103. Consistent. #Git #DevOps #100DaysOfCode #LearningInPublic #Infracodebase
To view or add a comment, sign in
-
-
“𝐃𝐨𝐧’𝐭 𝐜𝐨𝐧𝐭𝐫𝐢𝐛𝐮𝐭𝐞 𝐭𝐨 𝐭𝐡𝐞 𝐫𝐞𝐩𝐨 𝐰𝐢𝐭𝐡 𝐝𝐢𝐫𝐭𝐲 𝐜𝐨𝐦𝐦𝐢𝐭𝐬.” Early in my career, I rushed a fix. My PR looked like this: • Initial commit • Typo fix • Debugging • Updated README 1 • Updated README 2 • Plz work • Final FINAL fix It got clumsy and junky. The lesson? 𝐌𝐞𝐬𝐬𝐲 𝐡𝐢𝐬𝐭𝐨𝐫𝐲 = 𝐦𝐞𝐬𝐬𝐲 𝐭𝐡𝐢𝐧𝐤𝐢𝐧𝐠 (at least from the outside). 𝐂𝐥𝐞𝐚𝐧 𝐜𝐨𝐦𝐦𝐢𝐭𝐬 𝐛𝐮𝐢𝐥𝐝 clarity and make it easier to update features in the future. Commands every serious developer should master: → 𝐠𝐢𝐭 𝐬𝐭𝐚𝐬𝐡 Temporarily save your work to switch tasks instantly. → 𝐠𝐢𝐭 𝐜𝐨𝐦𝐦𝐢𝐭 --𝐚𝐦𝐞𝐧𝐝 Fix your last commit without adding noise. → 𝐠𝐢𝐭 𝐫𝐞𝐛𝐚𝐬𝐞 -𝐢 𝐇𝐄𝐀𝐃~𝐧 Clean, reorder, or squash commits into one clear story. → 𝐠𝐢𝐭 𝐜𝐡𝐞𝐫𝐫𝐲-𝐩𝐢𝐜𝐤 Move only the changes you need (perfect for hotfixes). → 𝐠𝐢𝐭 𝐫𝐞𝐟𝐥𝐨𝐠 Your safety net — recover “lost” commits anytime. → 𝐠𝐢𝐭 𝐫𝐞𝐬𝐞𝐭 --𝐬𝐨𝐟𝐭 𝐇𝐄𝐀𝐃~𝟏 Undo last commit, keep your changes ready. → 𝐠𝐢𝐭 𝐝𝐢𝐟𝐟 Review changes before you embarrass yourself. The truth? Good developers write code. 𝐆𝐫𝐞𝐚𝐭 𝐝𝐞𝐯𝐞𝐥𝐨𝐩𝐞𝐫𝐬 𝐩𝐫𝐞𝐬𝐞𝐧𝐭 𝐢𝐭 𝐜𝐥𝐞𝐚𝐧𝐥𝐲. Do you clean your commit history — or ship the chaos? 👇 #BackendEngineering #Git #CleanCode #DeveloperMindset #Coding #CodingIsTherapy
To view or add a comment, sign in
-
-
Stop naming your commits "fixed bug" or "final fix" (we both know it's not the final one anyway 😉). In a real engineering team, your Git history is your documentation. High-quality commits make you a 10x better collaborator. Here’s a quick hack: use the Imperative Mood. ❌ "I added a login feature" ✅ "Add login feature" It sounds like a command, which is exactly how Git treats it! 🚀 Want to practice this in a real dev environment? At KodeMaster AI, you don't just click buttons in a browser. You code in your own editor and push to Git, just like a real job. Build your muscle memory here: https://kodemaster.ai/ #CodingTips #Git #JuniorDev #WebDev #KodeMasterAI
To view or add a comment, sign in
-
-
"Why is this line like this?" Nobody on the team knew. The code did. 🔥 Happy Git Friday! Code review. Someone flagged a line in a config file that looked wrong. Not broken, just odd. A hardcoded value where a variable should have been. Nobody on the team remembered writing it. Nobody remembered approving it. It had been there so long it was just part of the landscape. Instead of guessing, I ran: git blame config.yml Every line in the file came back annotated with the commit hash, the author, and the date. That odd line? It was a workaround from two years ago. A specific bug in a dependency required a hardcoded value to avoid a crash. The bug was patched six months later. The workaround was never removed. No comment. No ticket reference. Just a line that made no sense anymore because the context was gone. git blame didn't just tell me who wrote it. It told me when, which commit, and gave me enough context to pull up the original PR and understand why. Two minutes of blame saved an hour of guessing and a potential rollback of something that turned out to be safe to remove. The Danger Zone (When Nobody Remembers Why): 🔹 Uncommented workarounds become mysteries the moment the original author leaves or forgets. git blame is the only way to recover the context when the code doesn't explain itself. 🔹 git log shows you commit history for the whole file. git blame shows you commit history per line. When you need to know why one specific line exists, log is too broad. Blame is surgical. 🔹 Removing a line you don't understand is risky. Blame gives you the commit, the commit gives you the PR, the PR gives you the discussion. That's the chain of context that makes the decision safe. ❓ Question of the Day: Which command shows who modified each line of a file and in which commit? Ⓐ git blame filename Ⓑ git who filename Ⓒ git log filename Ⓓ git diff filename 👇 Answer and breakdown in the comments! #Git #GitOps #DevOps #DamnitRay #QOTD
To view or add a comment, sign in
-
-
𝗪𝗵𝗲𝗻 𝘆𝗼𝘂𝗿 𝗚𝗶𝘁 𝗰𝗼𝗺𝗺𝗶𝘁𝘀 𝗴𝗲𝘁 𝗿𝗼𝗮𝘀𝘁𝗲𝗱... Ever wondered what your commit history 𝗿𝗲𝗮𝗹𝗹𝘆 says about you? 👀 I just tried https://lnkd.in/dUYPrtNy and let’s just say… my commits didn’t survive 😭 > “fix bug” > “final_final_v2_actually_final” > “misc updates” Yeah… I got called out 💀 But honestly, it’s a hilarious reminder of something we all ignore: 👉 Your commits tell a story 👉 Your Git history is your developer reputation 👉 And yes… naming things 𝘀𝘁𝗶𝗹𝗹 matters 𝗪𝗵𝘆 𝘁𝗵𝗶𝘀 𝗶𝘀 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝘂𝘀𝗲𝗳𝘂𝗹 (𝗯𝗲𝘀𝗶𝗱𝗲𝘀 𝘁𝗵𝗲 𝗹𝗮𝘂𝗴𝗵𝘀): * Forces you to rethink sloppy commit messages * Helps you build cleaner, more professional repos * Makes collaboration way easier * And… saves you from future embarrassment 😅 If you’re moving toward 𝗔𝗜-𝗮𝘀𝘀𝗶𝘀𝘁𝗲𝗱 𝗱𝗲𝘃𝗲𝗹𝗼𝗽𝗺𝗲𝗻𝘁 + 𝘀𝘆𝘀𝘁𝗲𝗺 𝗱𝗲𝘀𝗶𝗴𝗻, clean Git hygiene becomes even more important. Your commits are basically context for humans and machines. 💡 Try it yourself: Drop your repo in and see if you survive the roast: 👉 https://lnkd.in/dUYPrtNy 𝗕𝗲 𝗵𝗼𝗻𝗲𝘀𝘁: What’s the worst commit message you’ve ever written? #git #developers #codinghumor #gitkraken #softwareengineering #devlife #programmingmemes #cleancode #aiengineering #buildinpublic
To view or add a comment, sign in
-
-
Struggling with messy commit messages? Here’s a simple way to make them clean and professional 👇 ## 🔹 Use Standard Commit Types Using commit types makes your Git history easy to read and understand. 🎯 Common types: * feat → New feature feat: add user authentication * fix → Bug fix fix: resolve login redirect issue * refactor → Improve code (no behavior change) refactor: optimize API handling * style → UI / formatting changes style: update button spacing * docs → Documentation docs: add API guide * test → Testing test: add login unit tests * chore → Maintenance chore: update dependencies 💡 Why it matters: ✔ Easy to scan history ✔ Better team collaboration ✔ Cleaner debugging ✔ Helps automation (changelogs, releases) 🚀 Pro tip: One commit = one purpose. Split your changes. Bad ❌ feat: add login and fix bugs and update UI Good ✅ feat: add login API fix: correct validation style: improve UI 👉 Rule: Your commit should tell the story instantly. 💬 What’s the worst commit message you’ve ever written? 👍 If this helped, drop a like & follow for more dev tips! #Git #GitHub #WebDevelopment #Programming #SoftwareEngineering #CleanCode #Developers #CodeQuality #VersionControl #TechTips
To view or add a comment, sign in
-
-
Stop the "Stash & Switch" madness. 🛑 We’ve all been there: You’re deep in a feature, your workspace is a mess of half-finished logic, and suddenly... a critical bug hits production. Most devs reach for git stash. Some make a messy "WIP" commit. But there’s a better way that most people ignore: Git Worktree. Instead of flipping a single folder between branches, Git Worktree lets you "check out" multiple branches into separate folders simultaneously, all linked to the same local repo. Why is this a game-changer? ✅ Zero Context Switching: Keep your feature code open in one VS Code window and your hotfix in another. No stashing required. ✅ Parallel Testing: Run a heavy test suite or build process on one branch while you keep coding on the other. ✅ Code Reviews: Need to test a teammate's PR? Open it in a new worktree without touching your current progress. ✅ No More npm install Loops: If branches have different dependencies, worktrees keep their respective node_modules intact. No more re-installing every time you switch. The Magic Command: git worktree add ../hotfix-folder hotfix-branch It’s one of those "once you know it, you can't go back" tools. Are you still stashing, or have you made the switch to Worktrees? Let’s hear your workflow hacks in the comments! 👇 #Git #WebDevelopment #SoftwareEngineering #DevOps #ProgrammingTips #Efficiency
To view or add a comment, sign in
-
Most developers don’t realize this… but branch naming can make or break your team’s workflow 🚀 Clean code is important ✅ But clean Git branches? Even more underrated. After going through discussions on Stack Overflow and real-world dev practices, here are some simple GitHub branch naming conventions you should follow 👇 🔹 feature/ → for new features "feature/user-authentication" 🔹 bugfix/ → for fixing bugs "bugfix/login-crash" 🔹 hotfix/ → urgent production fixes "hotfix/payment-failure" 🔹 release/ → preparing for deployment "release/v1.2.0" 🔹 chore/ → minor tasks (no feature/bug) "chore/update-dependencies" 💡 Pro Tips: - Use lowercase & hyphens ("-") - Keep it short but meaningful - Avoid random names like "test123" 😅 - Follow a consistent pattern across the team 📌 Why it matters: - Easy collaboration - Better code reviews - Faster debugging - Clean project history Most teams struggle not because of code… but because of poor structure & discipline. 👉 What naming convention does your team follow? #Git #GitHub #Programming #Developers #CleanCode #SoftwareEngineering #DevTips
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development