Module 2 · Git: the 20 everyday commands · Lesson 13 of 16

Rebase, cherry-pick and stash

Replay a branch on a new base, copy one commit across, and park unfinished work.

In this lesson · about 24 minutes

  • Use git rebase to replay a branch on top of the latest main
  • Copy a single commit from another branch with git cherry-pick
  • Put unfinished changes aside with git stash, and bring them back with git stash pop

Key terms

Say the meaning to yourself, then tap a card to check.

Whiteboard · watch and try

Merge versus rebase

4 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

Tidy history, rescue a fix, and juggle unfinished work

Missions 0 of 10

  1. 1Switch to the contact-page branch.
  2. 2Replay contact-page on top of the latest main.
  3. 3Look at the history.
  4. 4Switch to main and merge contact-page.
  5. 5Look at the history of the experiments branch.
  6. 6Copy just the 'Fix heading colour' commit into main.
  7. 7Start some unfinished work: echo "Free wifi" >> index.html
  8. 8Put the unfinished change in the stash drawer.
  9. 9List what is in the stash.
  10. 10Bring the unfinished work back.
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.Why might you rebase your feature branch onto main before merging?

Question 2

2.Which commits should you NOT rebase?

Question 3

3.A bug fix sits on a branch full of half-finished experiments. How do you get only the fix into main?

Question 4

4.You are mid-change when an urgent bug comes in. What lets you switch tasks without committing half-done work?

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.