How to save current code changes without committing the changes in Git?
Published October 16, 2020
To save the code changes on a branch without committing in Git, First you need to add all the files so that any new files will be included if there is any. It can be done like this,
git add .
Then you can use the
Now all the uncommitted code will be saved to the Git Stash and all the uncommitted code will be removed from the files too but that doesn't mean it's gone, it's saved 😃.
After doing this operation, you can perform any operation in Git including, changing branches, creating new commits, etc.
To get back the saved code from the stash, you can use the
git stash pop
Now the uncommitted code which was in the stash is added again to the files.
Nifty Trick. Right 🌟. I use this all the time when I have uncommitted code and want to save them but not commit it when switching between branches.