← Back to all fixes
Committed to main instead of feature branch
The Issue
You ran `git commit` and `git push` but forgot to switch to your feature branch first.
Root Cause
Committed while on main. If not yet pushed, easy to fix. If pushed to a protected branch, need git revert.
How to Fix
If NOT yet pushed: `git reset HEAD~1` to undo the commit while keeping changes, then switch branches and recommitIf pushed to main: use `git revert <sha>` to create an undo commit and push itMove the changes to the right branch: `git stash` after reset, then `git checkout feature-branch && git stash pop`Prevent future accidents: enable branch protection rules on main to require PRs