learn git.
0/25 done
learn git/branches/course 15 of 25

git branch: create a universe

One command makes a new line of history, ready to stand on.

5 min read·3 sections·2 tasks
the key idea

git branch name creates a new label at your current commit — it does not move you there.

01Creating a branch

git branch feature creates a new label called feature, pointing at the commit you are standing on right now. Note carefully what does not happen: you do not move. You stay exactly where you were, on main, with the same files. A new label now exists, that is all — the universe is created but you have not entered it.

This no-side-effect quality is why branches are cheap. Creating one costs nothing — no files are copied, no project duplicated, nothing to clean up if you change your mind. The label weighs a few bytes. Compare that with copying a project folder, and you see why git changed how people work.

[bash]· create, then list
git branch feature
git branch

02Reading the list

git branch alone lists every label. The one with the star is where you are standing — right now, always, that star is the answer to where am I. A brand-new branch starts life pointing at the same commit as main: the two universes are identical until one of them gets a commit.

Branch names are a small craft of their own. Short, lowercase, dashes, named after the work — feature, fix-typo, new-login-page — not after people, dates, or version numbers. The name will be typed often and read in logs forever; make it describe the idea.

Deleting labels later

When a branch's work is merged and done, git branch -d name deletes the label. Git refuses if the branch still has unmerged commits — that refusal has saved careers. -D deletes anyway, for when you truly mean it.

03Where the branch starts from

A new branch is born pointing at wherever you are standing when you create it. Create feature while on main's newest commit, and feature begins its life there — sharing all of main's history so far, ready to add its own commits on top. If you had created it while standing somewhere older, it would have started there instead. Where you stand when you create is where the fork begins.

One tiny rule

git branch needs at least one commit to exist already — a label has to point at something. On a fresh repository with no commits, git refuses with fatal: not a valid object name. Take one photograph first, then start forking.

>>

Practice

Create your first branch without stepping onto it.

[practice]· a real terminal, safely simulated
practice terminal — everything here is simulated, nothing can break
type 'help' to see the commands this terminal understands
~/my-project (main) $
Your tasks1/2 done
  1. 01.Create a branch called feature.

    hint: Try: git branch feature

  2. 02.Confirm you are still standing on main.