Typorithm · easy

branch & switch

git-branchgitbranchswitchcheckout
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn branch & switch

0%

Branching

A branch is a movable pointer to a commit. git branch <name> creates one, git switch moves HEAD to it, switch -c does both at once, branch -d deletes a merged branch, and branch -a lists all branches including remotes. Branches are cheap.

In Git a branch is just a lightweight, movable pointer to a commit — creating one only writes a tiny reference, so branches are cheap to make and throw away.

git branch feature creates the pointer but leaves you where you are; git switch feature then moves HEAD onto it so new commits extend that branch. git switch -c hotfix combines create-and-switch into a single command.

When a branch's work has been merged, git branch -d feature deletes it. git branch -a lists every branch you have, including remote-tracking branches, so you can see the full picture.

01

A branch is a movable pointer to a commit.

02

git switch -c creates and switches in one step.

03

git branch -d deletes a merged branch.

git branch feature
git switch feature
git switch -c hotfix
git branch -d feature
git branch -a

Read the implementation

Connect each part of the code to the concept before you type.

1. Create a branch

git branch <name> creates a new pointer at the current commit without moving HEAD to it.

git branch feature

2. Switch to it

git switch moves HEAD to the named branch so new commits land there.

git switch feature

3. Create and switch

switch -c creates a branch and switches to it in one step.

git switch -c hotfix

4. Delete a branch

branch -d safely deletes a branch once its work has been merged.

git branch -d feature

5. List all branches

branch -a lists every branch, including remote-tracking ones.

git branch -a

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

branch & switch: Lesson & Practice · Typorithm | ApplyDjinn