Git · Middle · Question 52 of 75

You committed to main by mistake instead of a feature branch (not pushed). How do you fix it?

Explanation

git branch feature, then git reset --hard origin/main (or HEAD~1), then git switch feature. Since nothing was pushed, rewriting local main is safe.

Further reading

Problem with a question

Git · Middle · question 52

Test yourself

Take the Git · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz