Git - 将 master 中的更改提交到新分支

Git - committing changes in master to a new branch

场景

我有一个解决方案,克隆到我的本地机器上,我对主分支做了一些更改 (但我 还没有 提交它们).

问题

工作还没做完,暂时想把这些改动commit到自己的branch,但是一直在master工作

如何将master中的修改提交到自己的分支?

为了安全起见,stash先做你的工作,然后创建你的分支:

git stash
git checkout -b newbranch
git stash pop
# work, add and commit in newbranch
git checkout master
# resume working on master