I'm using Git. I accidentally started doing all of my code changes on Master. How can I create a branch "new_feature" and have all of my changes moved to the "new_feature" branch and off of master?
If you've already committed your code, you need to only run git checkout -b new_feature
. This will both create your new branch and switch you to that new branch.
If you have not yet committed your changes, run git checkout -b new_feature
then commit your changes.
If after creating your new branch and committing your code, you need to revert your master branch:
git checkout master # switch to the master branch
git reset --hard origin/master # revert master to the current origin/master
Be aware that git reset --hard
will cause you to lose any uncommitted changes.
If you haven't committed yet to the master branch. do a git diff
to create a patch.
create new branch
git checkout -b new_branch
and apply the patches using git apply
You can follow this question in order to understand better how to create patches from uncommited / unstaged changes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With