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

5 steps
Press Play and the tutor will talk you through it while writing on the board. Pause any time to write on the board yourself.

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

  1. 1List the branches.
  2. 2Show the history of all branches together.
  3. 3Create a branch called new-menu.
  4. 4Switch to new-menu.
  5. 5Create menu.txt: echo "Espresso, Latte, Tea" > menu.txt
  6. 6Stage and commit it.
  7. 7Go back to main.
  8. 8Merge new-menu into main.
  9. 9Use the older command to look at the contact-page branch.
  10. 10Return to main with checkout.
  11. 11Merge contact-page into main.
  12. 12Delete the new-menu branch, now that it is merged.
sam@practice-box:~/website

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.

ce42faeHEAD → mainorigin/mainAdd opening hours
e6118b4experimentsExperiment: hide footer
dae34e8Fix heading colour
b85c626contact-pageorigin/contact-pageLink contact page from home
84b362cAdd contact page
b644ba3Add phone number to footer
534d516Add styles
dd28f37Add home page

☁ 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

Question 1

1.Which command creates a branch called fix-logo AND moves you onto it?

Question 2

2.You are on main and run git merge feature. What happens?

Question 3

3.What is a fast-forward merge?

Question 4

4.git branch -d old-idea says 'not fully merged'. What does that tell you?

Quiz score: 0 of 4

Tip: answer every quiz question correctly first.

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.