Git Tips Slides
PageUp x2: previous · PageDown x2: next · Home: index

Accidentally Commit on Branch main

You accidentally created a commit on your local main branch. That was a mistake because every change should be done via a pull request. You have not pushed your changes yet.

Solution: create a feature branch, delete your local main, and recreate it from origin.

# Create the branch you want to use for your feature.
git switch -c feature-foo

# Delete your `main` branch.
# Relax: You still have the "main" branch on origin (like Github/Gitlab/Codeberg/...)
git branch -D main

# re-create branch "main" from origin
git switch main

# Now develop on your feature branch.
git switch feature-foo