Need to switch tasks but don’t want to lose your current changes?
Git stash is your go-to solution for saving work temporarily without committing it.
In this guide, let's walk you through how to use Git stash in the terminal, so you can safely pause your work and pick it up again whenever you’re ready.
Steps to follow:
1. Check your changes before stashing.
2. There are two simple ways to save temporary changes:
3. The '-m' flag lets you add a message to your stash, making it easier to identify its purpose later.
4. To save your changes temporarily, use the 'git stash' command.
5. You can see a list of all stashes using 'git stash list'.
Note: This will show you a list of stashes with their corresponding names, like stash@{0}, stash@{1}.
6. To continue working, use 'git stash apply' to reapply your stashed changes.
By default, it restores the latest stash ('stash@{0}'), but you can specify any stash, e.g., 'git stash apply stash@{1}'.
7. After applying a stash, it stays in the stash list. If you don't need it anymore, remove it with 'git stash drop'.
Note:
- To remove a specific stash, use 'git stash drop stash@{1}'.
- To apply and remove a stash at once, use 'git stash pop', or for a specific stash, 'git stash pop stash@{0}'.
That's All!
We have successfully stashed, applied, and dropped your temporary changes.
Using Git stash is an easy way to keep your working directory clean while switching contexts. Now that you know how to stash and reapply your changes, you’ll have the flexibility to manage multiple tasks seamlessly without losing any progress.
Still have questions?
Send an email to archana@leadwalnut.com, OR
Book a FREE consultation with an expert developer here.