Skip to content

Whoopsies


Setup

You've been working on an experimental feature for your latest project, and you accidentally committed your changes to the main branch. You meant to commit them to a new branch named olivebranch. Whoopsies!

cd path/to/parent/dir/
mkdir beluga && cd beluga && git init
touch xyz.py
git add xyz.py
git commit -m "initial commit"
echo "Half-baked experimental feature" > xyz.py
git add xyz.py
git commit -m "testing new feature X"
echo "<more feature logic>" >> xyz.py

State of things

beluga/
  xyz.py
bill@gates:~$ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   xyz.py

no changes added to commit (use "git add" and/or "git commit -a")
bill@gates:~$ git log --oneline
e5d13ef (HEAD -> main) testing new feature X
b406033 initial commit

Challenge

Fix your mistake! Move the commit out of the main branch and into a new branch named olive. (olive's parent should be the commit you made prior the mistake commit.) Switch to the olive branch 🫒 so that you can carry on with your work. Make sure you don't lose those uncommitted changes!