Git move uncommitted changes to a new branch

For instance, if you're working on a dev branch, make some changes, before you make any commits, you decide these changes should stay on a new branch.

git status

modified: XXX
modified: YYY

Say you'd rather create a new branch newFeature.

$ git checkout -b newFeature
Switched to a new branch 'newFeature'
M       XXX
M       YYY
git status

modified: XXX
modified: YYY

Now on branch newFeature just do commit and push:

git add XXX YYY
git commit -m "Some Message"
git push --set-upstream origin newFeature

And when you turn back to dev, you'll find the uncommitted changes are now gone in dev, and you get all them in newFeature.

$ git status
On branch dev
Your branch is up to date with 'origin/dev'.

Alternatively:

You can just commit in dev, and then do git cherry-pick.

你可能感兴趣的:(Git move uncommitted changes to a new branch)