Press "Enter" to skip to content

Git — Temporarily store changes without committing

This post is covers how to use git stash. If you do any development work using git, this is a must-know command.

Lets say you are writing code to implement a new feature on branch new_feature when you get a report of a bug that you must fix on branch stable. If you have local changes but are not yet ready to commit them there are a few options available to you.

One option (that I do not recommend) is to copy the files with local changes to a directory outside of the repository. You can checkout these files to overwrite the changes inside the working directory once you are sure that you have these changes backed up elsewhere.

A much better and easier way to handle this situation is to use git stash. Simply type git stash. This will store away your local changes so that your working directory is clean and you are free to switch to another branch. Once you are ready to resume work on the uncommitted changes, type git stash pop to get the modified files back in your working directory.

Be First to Comment

Leave a Reply

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