Git - working on wrong branch - how to copy changes to existing topic branch
Sounds like all you need is the following:
git stash
git checkout branch123
git stash apply
Then you should be back on your own branch without touching the master branch.
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.