Getting into trouble with Git
When you start a new implementation in git, you usually create a new branch, checkout to it, and start working on it. Then, when you're done, you commit and push to the new branch.
But sometimes, you forget to create a new branch. Here's how to deal with it.
This is a workaround for that.
The idea is to move the commit to the newly created branch (while keeping it) and revert the master branch to the previous commit.
The flow is as follows
Translated with www.DeepL.com/Translator (free version)
Implemented in master ↓ Commit and push to master ↓ Delete ↓ Create a new branch and checkout ↓ Checkout ↓ Return to master ↓ Return to master ↓ reset in master
Create a new branch
After you coomit to master, you can create a new branch
git checkout -b NewBranch Switched to a new branch 'NewBranch'
A new branch called NewBranch has been created, and you can see that you are now on the master branch
git branch NewBranch * master
Checkout and return to master.
At this point, master and NewBranch should be in the exact same state.
From this state, let's go back to master with checkout.
git checkout master
Resetting while in the master branch
When you get back to master by checkout, use git reset to cancel the master commit.
git reset --hard HEAD~1
Now, NewBranch will have the latest commit, and master will have the previous commit.