this happens to every developer time-to-time. You start coding a new feature and forget to branch first locally.
So if that happens is there a way I can say hey, transfer these uncommitted (or committed - yea I know those are both two scenarios which I'd like to cover with this) to a new branch for me locally so I don't have to back them out and copy my changes to a new branch to be able to carry on my way?
When you change a file in your work-tree, nothing happens to the copy in the index. It still matches the copy in the commit you chose. You have to run git add to copy the file from the work-tree, to the index.
Using the git checkout Command The git checkout -b <BranchName> command will create a new branch and switch to it. Moreover, this command will leave the current branch as it is and bring all uncommitted changes to the new branch.
If you haven't commited your changes yet, you can switch to a new branch prior to committing.
git checkout -b my-new-branch
This will create a new branch called my-new-branch
and immediately check it out.
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