How to save current code changes without committing the changes in Git?

October 16, 2020 - 1 min read

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

git stash

command.

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

command.

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.

Meaning of Stash according to Cambridge Dictionary _to store or hide something, especially a large amount: _

Feel free to share if you found this useful 😃.