INTRODUCTION
Branches
Try an idea on a copy of the timeline.
press Enter ↵
💾 Save points on main
  1. Add a to-do listf02c54dmainyou are here
  2. Add my ideasadc97b5
  3. My About Me page8fa9095
✓ Everything is saved.

Windows PowerShell (practice mode: nothing here touches your real computer)

 

Lesson 55: Branches

Level 7, Save Points: Git and GitHub. Try an idea on a branch, then merge it into main. The new word: branch. It follows lesson 54, Time travel with Git. Next comes lesson 56, GitHub and git push.

What the lesson explains

Branches. Try an idea on a copy of the timeline.

Try ideas safely. main is the real one. A branch is a safe place to try. main the real one; a branch a copy; merge bring it back.

What you do first

Make a branch. In the practice terminal, type git branch at the prompt PS C:\Users\you\Documents\my-site> and the computer answers: * main.

The files on the practice computer

This lesson works in one folder. At the start, Documents\my-site holds images\, ideas.txt, index.html, style.css, todo.txt.

Along the way you type git branch, type git switch -c dark-mode, type echo "body { background-color: black; color: white; }" >> style.css, type git add style.css, type git commit -m "Dark mode", type git switch main, type git merge dark-mode, type git switch -c big-title, type echo "h1 { font-size: 60px; }" >> style.css, type git commit -m "Big title" and type git merge big-title. Lesson 56 opens with the files just as you leave them.

What you practise

Try it, "Make a branch": In the practice terminal, type git branch at the prompt PS C:\Users\you\Documents\my-site> and the computer answers: * main. Then: In the practice terminal, type git switch -c dark-mode at the prompt PS C:\Users\you\Documents\my-site> and the computer answers: Switched to a new branch 'dark-mode'.

Try it, "Change it on the branch": In the practice terminal, type echo "body { background-color: black; color: white; }" >> style.css at the prompt PS C:\Users\you\Documents\my-site>; the prompt then reads PS C:\Users\you\Documents\my-site>. Then: In the practice terminal, type git add style.css at the prompt PS C:\Users\you\Documents\my-site>; the prompt then reads PS C:\Users\you\Documents\my-site>. Then: In the practice terminal, type git commit -m "Dark mode" at the prompt PS C:\Users\you\Documents\my-site> and the computer answers: [dark-mode 31d2355] Dark mode / 1 file changed.

Try it, "Back to main": In the practice terminal, type git switch main at the prompt PS C:\Users\you\Documents\my-site> and the computer answers: Switched to branch 'main'. Then: In the practice terminal, type cat style.css at the prompt PS C:\Users\you\Documents\my-site> and the computer answers: body { / background-color: lightyellow; / } / h1 { / color: purple; / }.

Try it, "Merge it": In the practice terminal, type git merge dark-mode at the prompt PS C:\Users\you\Documents\my-site> and the computer answers: Updating f02c54d..31d2355 / Fast-forward / style.css.

In your head, "Is main safe?": On a branch, you break the page. Is main broken too? The answer: "No: main stays safe".

Challenge, "A big-title idea": Try a big title on a branch called big-title, save it, then merge it into main. Starting at PS C:\Users\you\Documents\my-site>, one way takes 6 commands: git switch -c big-title; echo "h1 { font-size: 60px; }" >> style.css; git add style.css; git commit -m "Big title"; git switch main; git merge big-title (par: 6).

What PlayBuddy and PlayType say

PlayBuddy: "A branch is a safe copy of your timeline, for trying ideas."

PlayType: "Happy with the idea? Merge it back into main."

Help in every lesson

Everything happens on a pretend computer in your browser, so nothing touches your real files. PlayBuddy and PlayType stand beside the board, cheer you on and say when it is your turn.

A green ring shows where to click the first time. After that you do it on your own, and if you slip twice the ring comes back.

Stars

The lesson has 10 things to do. Up to one slip in ten gives three stars, up to one in four gives two, and finishing always gives at least one. Stars and progress are saved in this browser only; there is no account.

About DayOneCode

DayOneCode is an independent learning site, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic.