Ben Gorman

Ben Gorman

Life's a garden. Dig it.


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
git add
git commit -m "initial commit"
echo "Half-baked experimental feature" >
git add
git commit -m "testing new feature X"
echo "<more feature logic>" >>

State of things

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)
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


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!


This content is gated

Subscribe to one of the products below to gain access