Branches and merges
What a branch is
Understand a branch as a movable name that points to the latest commit in one line of development.
A branch is a readable name that points to a commit.
Suppose main points to commit C:
A---B---C main
Creating a branch named add-search creates another reference to the same commit:
A---B---C main, add-search
No files are copied. A branch is lightweight because Git only needs another reference.
HEAD and new commits
HEAD normally points to the branch you currently have checked out. If HEAD points to add-search and you commit, Git creates a child of C and moves only add-search:
A---B---C main
\
D add-search <- HEAD
The main reference remains at C. The commits are not “inside” folders called branches. References give Git starting points for walking the commit graph.
That is why switching branches feels instant. Git updates your working tree to match a different commit. It does not copy the whole project.
Think of branches as movable bookmarks in a commit graph. Deleting a branch name does not delete the commits it pointed to, as long as another reference still reaches them.
Multiple branches can point at the same commit. That is exactly what happens when you run git switch -c feature from main. Both names start on the same snapshot until one of them gets a new commit.
Tags work like branches but stay fixed on one commit. Release tags such as v1.0.0 mark a snapshot you want to find again later. Branch names move; tags usually do not.
Inspect the current branch with:
git branch --show-current
git log --oneline --decorate --graph --all
Try this on your own project: draw three commits and two branch references. Move HEAD to one branch, add a commit, and predict which reference moves.
Lesson completed