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 🌟.
First add all the files so that any new files will be included if there is any. It can be done like this,
git add .
To move uncommitted code to a different branch, you can use the
command to temporarily store the code to Git Stash.
Then you need to change to the branch you need to move the code using this command,
git checkout name_of_branch
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.