Skip to main content
← Back to course

What a Branch Actually Is

A branch is just a movable pointer to a commit — genuinely that simple underneath, even though it enables working on completely isolated lines of history.

main (or master on older repos) is just a branch, not a special file or folder. There's nothing structurally different about it compared to any branch you create — it's a convention (usually protected, usually the "real" deployable state) rather than a technical distinction.

git branch <name> creates a new branch; git switch <name> (or the older git checkout <name>) moves you onto it. Once switched, every commit you make happens on that branch specifically — the other branches don't see it until you merge.

git switch -c <name> creates and switches in one step — the shortcut you'll actually use most often, since you almost always want to start working immediately after creating a branch.

Branches are cheap — genuinely, not just "relatively" cheap. Creating a branch doesn't copy your project; it's a tiny pointer, created instantly regardless of how large your repository is. This is why "just make a branch for it" is reasonable advice even for a small, throwaway experiment.

git branch (no arguments) lists all local branches, with * marking your current one. git branch -d <name> deletes a branch once you're done with it (Git refuses if it has unmerged changes, as a safety check — -D force-deletes if you're certain).

Why this matters for you

Branches are what let you work on a risky experiment, a bug fix, and a feature simultaneously without any of them interfering with each other or with a stable main — that isolation is the entire point.

▶️ Before the next lesson

In your practice repository from the last course, create a new branch with git switch -c try-something and confirm git branch shows it as your current branch.