Why Branches Exist
What this is. A branch is a separate line of history. You can make changes on it, commit them, and the branch you came from is completely untouched until you decide to merge.
The point is not organization. The point is that you can try something without risking what already works.
The commands.
git branch lists branches, marking the current one.
git branch name creates one.
git switch name moves to it.
git switch -c name creates and moves in one step, which is what you will actually type.
git merge name brings that branch's commits into the current one.
✦ Branches are cheap, and that is the whole design
In older version control systems a branch meant copying the entire project and merging was genuinely painful, so people avoided branching. Git made branches almost free, which changed the workflow: you branch for a two line fix without thinking about it. If a branch turns out to be a bad idea, you switch away and delete it, and nothing was ever at risk.
Mark this lesson complete
Signed in, your progress follows you to every device.