git – commit modified files from one branch to another branch
I have 2 branches:
- I made some changes while checked out to branch
- I don’t want to add/commit these changes in
sprint1, I want to add/commit them on
- I tried to checkout
devwithout committing changes in
sprint1first, but the checkout fails;
My question is: How can I bring those changes in
dev without committing them to
2 Solutions collect form web for “git – commit modified files from one branch to another branch”
git stash git checkout dev git stash apply git commit
You can merge your local modifications into the branch you want to checkout.
sprint1 branch do:
git checkout --merge dev
This will merge the local modifications of the working directory into the
dev branch and switch to it. The changes are just merged and not committed. So you can now go on as usual.
git add .... git commit
From the git checkout documentation
When switching branches, if you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command refuses to switch branches in order to preserve your modifications in context. However, with this option, a three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch.