Git: Move all non-pushed commits to a new branch
Note: this the first part of the wiki which shows how to only push the last commit to a remote: https://yctct.com/git-push-specific-commits-only-remote
# Note: Any changes not committed will be lost.
$ git branch newbranch # Create a new branch, saving the desired commits
$ git checkout main # checkout main, this is the place you want to go back
$ git reset --hard HEAD~3 # Move main back by 3 commits (Make sure you know how many commits you need to go back)
$ git checkout newbranch # Go to the new branch that still has the desired commits
or instead of step 3:
$ git reset --hard a1b2c3d4
were the last bit is the hash of the commit you want to reset to.
personal computing command-line interface (cli) gnu linux trisquel shell literacy office applications wiki git