Yes, it is possible.
If you have not yet done any commit
Right now you are in master
. If you type git status
you will see a list of files that have been modified but not committed .
Simply create the branch:
git checkout -b nueva_rama
This command creates it and automatically takes you to it, taking all those changes with you.
Indeed, if you do git status
again you will see that those changes appear there, so when doing a commit
will be added to that branch nueva_rama
, not% master
.
If you have already done some commit
In this case, you must first undo it. As you read in How can I undo the last commit in Git? , use:
git reset HEAD~1
or more times if there are more commits. As of that moment, git status
will show those changes again in the "uncommitted" state.
Then we are again in the previous point If you have not yet done any commit
, so follow those steps.
You should also bear in mind that in master
you will have a few commits to undo. Therefore, you must return to the previous state by doing git checkout <número del último commit válido>
.