Take the 2-minute tour ×

How can I do this 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?

share|improve this question
LoL I always make this mistake –  Pineapple Under the Sea Aug 5 '12 at 22:02

5 Answers 5

up vote 351 down vote accepted

Since your files are not yet committed in branch1:

git stash
git checkout branch2
git stash pop


git stash
git checkout branch2
git stash apply x    # to select the right one
share|improve this answer
Thanks - that's exactly what I was looking for –  solsberg Feb 17 '09 at 14:44
This does not work for me. If I make a set of changes accidentally on master, and they are uncommited, but I wanted to apply them to other branch develop, if I try git stash then it will not allow me to checkout develop. –  prpl.mnky.dshwshr Apr 11 at 21:07


git checkout branch2


git checkout -m branch2


git reset
share|improve this answer

Here is a shorter alternative to the previosly mentioned stash approach:

Temporarily move the changes to a stash.

git stash


git stash branch new_branch_name

Then add and commit the changes to this new branch.

share|improve this answer


share|improve this answer


How to Commit to a Different Branch in git



git merge master
git stash -u
git checkout master
git stash apply
git reset
git add example.js
git commit
git checkout .
git clean -f -d
git checkout my_branch
git merge master
git stash pop








share|improve this answer
I am using 2 accounts in order to separate my work from my personal account. I need to be notified at work when I ask a work-related question. If there's no answer, and I have to research it, I'll take a minute to answer the question. I consider this morally acceptable. I later refined the answer on my own time and answered this question with it, and updated the original answer. That's why they're the same. If I merge the two accounts, would I still be able to keep work and personal separate? I am going out of my way to act ethically here, the least the mods could do is ask before deleting. –  vladkornea Aug 15 at 22:09
They could ask rather than treating me as a criminal. I edited the deleted answer yesterday to add an explanation. Nothing was done about it. I tried voting to undelete, but was told "A moderator has deleted this post and it cannot be undeleted". Not only am I being treated as a criminal without any evidence of guilt, but my appeal is ignored. This is not right. –  vladkornea Aug 15 at 22:21

Your Answer


