Update 2020 / Git 2.23
Starting with this version of Git, replace the checkout command with:
git switch -c <new-branch>
The behavior is identical and remains unchanged.
Before Update 2020 / Git 2.23
Use the following:
git checkout -b <new-branch>
This will leave your current branch as it is, create and checkout a new branch and keep all your changes. You can then stage changes in files to commit with:
git add <files>
and commit to your new branch with:
git commit -m "<Brief description of this commit>"
The changes in the working directory and changes staged in index do not belong to any branch yet. This changes the branch where those modifications would end in.
You don't reset your original branch, it stays as it is. The last commit on
<old-branch> will still be the same. Therefore you
checkout -b and then commit.