brewly — Ch.4 · Committed on the wrong branch
Exercise 4 of 9
Before you start
A branch is just a name
Your commit is on main, but should be on its own branch. First give it a second name, then move main back.
git branch <name> creates a branch at the commit you are on without switching to it.
Then git reset --hard HEAD~1 moves main back. The commit stays safe, because the new branch still points at it. Check git status first: a hard reset overwrites uncommitted changes.
- git status
- make sure nothing is uncommitted
- git branch <name>
- name the current commit
- git reset --hard HEAD~1
- move the current branch one commit back
- git switch <name>
- continue on the new branch
- git log --oneline --graph --all
- check where the branches point
You can reopen this any time with “Lesson”.
# BrewlyOrder coffee ahead.## Team- Maya (lead)- Alex (frontend)
Graph
- 75ac9c1 Count loyalty stampsHEAD → main
- 1354d06 Add menu pageorigin/main
- 619eb3b Style the order button
- 5fc44ac Initial commit