GIT stash command
In this tutorial, we will describe the git stash command. Git stash command is very useful when you have changes that are not ready to commit. The situation may be that you have done some code changes and wan to switch from where you have started. You can do stash the changes and get back to the starting point. The stash will save the uncommitted changes to a temporary place. After the stash command, you can do the changes and apply the changes later whenever you want.
Prerequisites To understand the git stash command :
- What is the git repository?
- git clone command
- git commit command
- git status
- git pull command
- git push command
Example scenario for git stash command:
We can better understand the need for git stash command with the help of an example. Suppose you have checked out a repository on the local machine. After checkout, you are making the changes to complete a feature. Meanwhile now you need to make the fix in the original code.
One way that you check out the code at a new place and make changes and push the changes in the remote repository. Now again move to the original local directory, which has your uncommitted changes. If you try to update the code, it will ask to commit the changes, but changes are dirty( not completed/not tested).
With a git stash command, you can save the local changes and move to the original state of the code and can do a git pull to get the changes. Later you can apply the local changes after the update. This will not add any dirty commitment to the working repository.