• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Twitter GitHub
You are here: Home / Dev Tips / What is a Git Branch?

What is a Git Branch?

Last updated on February 7, 2021 by Sal Ferrarello

While my mental model visualizes a Git branch as a stack of building blocks, in actuality a Git branch is a pointer to a single commit.

How Can a Single Commit Represent a Branch

Since each commit points back to its parent (see What’s a Git Commit Parent), if we know the most recent commit (i.e. the top most block), we can trace our way back to determine the entire stack of blocks.

Under the Hood

Each branch is a text file stored in the hidden directory .git/refs/heads/.

After cloning my example Git branch with blocks repo. I can look at the file that represents the main branch with

less .git/refs/heads/main

This displays the following line (which is the commit hash for the commit at the tip of the main branch).

2b3a38be1df114556a019986dcfbfedda593925f

I can see the abbreviated version of this commit hash (2b3a38b) at the tip (top) of our branch when I run git log --oneline.

2b3a38b (HEAD -> main, origin/main) B
ec6a2c7 A
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Programming Tagged With: Git

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2021 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in