How to move uncommitted code to a different branch in Git?

Published October 18, 2020

Many times I had this problem where I start implementing a feature in my main branch only to realize that this is not the appropriate branch to implement it 🤯. The following tip will quickly help you to recover from this situation 🌟.

Step 1

To move uncommitted code to a different branch, you can use the

git stash

command to temporarily store the code to Git Stash.

Step 2

Then you need to change to the branch you need to move the code using this command,

git checkout name_of_branch

Step 3

After changing to the branch you can use,

git stash pop

command to get the code from the stash.

Now, you will get the uncommitted code written to files in the new branch.

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter