0
0
Gitdevops~3 mins

Why What a branch is (pointer to a commit) in Git? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could instantly jump back to any version of your work without rewriting or losing anything?

The Scenario

Imagine you are writing a story on paper, and every time you make a change, you write it down on a new page. But you only keep track of the last page you wrote on, and you have no easy way to jump back to an earlier version or try a different ending without rewriting everything.

The Problem

Manually tracking changes like this is slow and confusing. You might lose track of which page is the latest, accidentally overwrite your work, or struggle to compare different versions. It's easy to get lost and waste time fixing mistakes.

The Solution

A branch in Git acts like a simple pointer to a specific commit (a saved version). Instead of rewriting or copying everything, you just move the pointer to the new commit. This makes it easy to switch between versions, try new ideas, and keep your work organized without confusion.

Before vs After
Before
Write changes on new pages and remember the last page number.
After
git branch feature
# 'feature' points to a commit, easy to switch and track
What It Enables

Branches let you work on different ideas safely and switch between them instantly, like having bookmarks for your story versions.

Real Life Example

A developer creates a branch to add a new feature without disturbing the main code. If the feature works, they merge it; if not, they simply delete the branch without affecting the main story.

Key Takeaways

A branch is a simple pointer to a commit.

It helps track different versions easily.

Switching branches is like jumping between saved story pages.