One mistake is to have changed in the [master] branch instead of [mymain]. This can be fixed with this bash script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # check the branch that you committed to by accident, in this case, is master git checkout master # reset the branch back one commit git reset --soft HEAD^ # use stash to record the current state of the working directory git stash # checkout the branch it should be in, in this case, is mymain git checkout mymain # apply the stash git stash apply # commit the changes git commit -am "main commit" # then push the changes to our main branch git push origin mymain # checkout the original branch, in this case, is master git checkout master # the last step is to force push the commit deletion to the original branch. git push --force origin master |