Git reset back to master/main

5 min read
Git reset back to master/main

If you are ahead of master, to reset and save your changes.

git reset --soft HEAD~ # reset to the last commit
git stash              # stash all the changes in the working tree 
git push               # push changes 
git stash pop          # get your changes back