Module 2 · Git: the 20 everyday commands · Lesson 12 of 16
Branches: branch, switch, checkout, merge
Work on ideas side by side without breaking the main version, then bring them together.
In this lesson · about 24 minutes
- Create, list and delete branches with git branch
- Move between branches with git switch (and the older git checkout)
- Combine a branch into another with git merge
Key terms
Say the meaning to yourself, then tap a card to check.
Whiteboard · watch and try
Branches are labels on a line of save points
Tip: press Pause, then use the pen to work along on the board. Space plays and pauses; Ctrl+Z undoes your last mark.
Practice terminal · missions
A new menu page and a contact page
Sam's repository already has two side branches: contact-page (finished) and experiments (Mia's ideas). Watch the branch graph as you work.
Missions 0 of 12
- 1List the branches.
- 2Show the history of all branches together.
- 3Create a branch called new-menu.
- 4Switch to new-menu.
- 5Create menu.txt: echo "Espresso, Latte, Tea" > menu.txt
- 6Stage and commit it.
- 7Go back to main.
- 8Merge new-menu into main.
- 9Use the older command to look at the contact-page branch.
- 10Return to main with checkout.
- 11Merge contact-page into main.
- 12Delete the new-menu branch, now that it is merged.
Type a command and press Enter. Try help to list commands. Tab finishes names, ↑ repeats.
Repository ~/website · on main
1 · Working folder
The files you edit
- README.mdsaved
- hours.txtsaved
- index.htmlsaved
- style.csssaved
2 · Staging area
Packed for the next commit
- (nothing staged: use git add)
3 · Commit history (this computer)
Each dot is a saved snapshot. Labels are branches, tags and what you last heard from origin.
☁ Remote: origin
https://github.example/sam/website.git
- maince42faeAdd opening hourssame as yours
- contact-pageb85c626Link contact page from homesame as yours
Check your understanding0 of 4 correct
Quiz score: 0 of 4
Written by Noviq Academy in its own words. The practice terminal is a simulation that runs in your browser: it imitates Linux (Ubuntu-style output) and Git closely, but it is not a real computer, and real output can differ slightly. The servers, people, web addresses and GitHub addresses in the labs are made up. Linux is a trademark of Linus Torvalds; Git and GitHub belong to their owners. Read-aloud uses your device's built-in voices.