Git branches: Not what you think they are

Git branches actually don’t exist the way most people think. Over the years, I’ve trained many people to use Git. One of the most common misconceptions I’ve noticed - even among experienced engineers - is how they understand what a “branch” really is. In everyday life, we think of a branch as something linear, and a sequence of commits seems to fit that idea perfectly. This mental model makes it easy to imagine “main” and “develop” as two parallel chains of commits evolving side by side. Even the famous Git Flow diagram reinforces that image — but it’s important to remember that it has nothing to do with real Git commit graphs. It uses its own symbolic “language” to describe a branching strategy, while many people unconsciously expect it to follow the same visual rules as the commit graphs we see in Git clients and history viewers. And that’s where the confusion begins. A branch in Git is not a chain of commits. It’s just a movable label (a reference) attached to a commit - just like a tag. The difference is that while a tag permanently points to a specific commit, a branch reference automatically moves to the newest commit each time you make one from the commit it’s pointing to. This leads to several important implications: * After merging, if you merge a feature branch into “develop” without squashing, there’s no reliable way to tell which part of the history belonged to the feature branch or to “develop.” Git - ironically, a system built to track history - does not track the history of your commit tree itself. * Deleting a branch does not delete any commits. It simply removes the label (reference) to the commit. The commit chain remains in the repository and can still be accessed by its hash until Git’s garbage collector eventually removes it (typically after about 30 days). * Merging into a branch where no new commits exist (for example, “develop” into “main”) don’t create parallel lines. The “main” branch reference just moves forward to the latest commit that “develop” already points to. So next time you visualize Git branches, don’t imagine “chains.” Think of a single commit graph where branches are just labels that jump. #Git #SoftwareDevelopment #VersionControl #ProgrammingConcepts #CleanCode #Mentoring

  • diagram

To view or add a comment, sign in

Explore content categories