The accepted answer is the most thorough, but there is a special case where you can simplify. If the files you have modified in the working directory are identical in both master
and branch123
you can simply do
git checkout branch123
No need to stash anything, since the default behavior of checkout
is to NOT overwrite modified files in your working directory, so you won't lose anything. (This was actually mentioned in the comments first by Cascabel)
As other people have mentioned in the comments, if branch123
doesn't exist yet, you can do
git checkout -b branch123
Based on what I found here.