Moving unstaged changes to another branch in Git

If you move around between different branches a lot in Git, you might find that you accidentally make some changes on the wrong branch and only realise this when it comes to stage/commit them. As always, Git has a solution.

Assuming you haven’t staged any changes (using git add), the following three commands will switch everything to a new branch:


git stash
git checkout correct-branch
git stash pop

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.