How can I do the following in Git?
My current branch is branch1 and I have made some local changes. However, I now realize that I actually meant to be applying these changes to branch2. Is there a way to apply/merge these changes so that they become local changes on branch2 without committing them on branch1?
Since your files are not yet committed in branch1
:
git stash
git checkout branch2
git stash pop
or
git stash
git checkout branch2
git stash list # to check the various stash made in different branch
git stash apply x # to select the right one
As commented by benjohn (see git stash
man page):
To also stash currently untracked (newly added) files, add the argument
-u
, so:
git stash -u