← Lessons/Branching & Merging
← Branching & Merging

Create a branch

Learn

Create a branch

git switch -c hotfix    # create a branch called "hotfix" and switch to it
git branch              # list branches; * marks the one you're on

git switch -c <name> is the modern way to create-and-switch (older guides use git checkout -b). A new branch starts at the commit you're on, so at first it's identical to main: it only diverges once you commit on it.

Type each command into the terminal and press Enter.

Create and switch to a branch called feature with git switch -c, then run git branch to list branches — feature should be marked current with *.

sandbox@opspath: ~
OpsPath sandbox · Debian GNU/Linux 12 · GNU bash 5.2
Your session carries over: files, commits, branches and cd all stick.
Press restart (top right) to go back to this mini lesson's starting point.
Type a command and press Enter. ↑/↓ history · Ctrl+L clear · Ctrl+C cancel line
# ── Step 1 · Create a branch ──
# Sign in to run commands — it's free.