If you don’t have time to read but want to know what’s there in this series. Find the quick read 👇
On this Series
We are going to see the commonly used Git snippets for the repository which will make you from Noob to Pro.
The Git Repository snippets that we are going to look at in this series are
Local Repository
Branches
Commits
Module
Stash
On this Post
In this post, we are going to see the topic Stash which has the following sub-topics like
Create a Stash
List all stashes
Apply a Stash
Apply the latest Stash
Delete a Stash
Delete all Stashes
1. Create a Stash
Saves the current state of the working directory and indexes into a new stash.
Use
git stash save
to save the current state of the working directory and index it into a new stash.You can optionally use the
-u
option to include untracked files.You can optionally provide a
<message>
for the stash.
git stash save [-u] []
# Example
git stash save
# Creates a new stash
git stash save -u
# Creates a new stash, including untracked files
git stash save "Bugfix WIP"
# Creates a new stash with the message "Bugfix WIP"
2. List all stashes
Displays a list of all stashes.
- Use
git stash list
to view a list of all stashes.
git stash list
# Example
git stash list
# stash@{0}: WIP on patch-1: ee52eda Fix layout bug
3. Apply a Stash
Applies a specific stash.
- Use
git stash apply <stash>
to apply the given<stash>
.
git stash apply
# Example
git stash apply stash@{1} # Applies `stash@{1}`
4. Apply the latest Stash
Applies the latest stash.
- Use
git stash apply
to apply the latest stash.
git stash apply
# Example
git stash apply # Applies the latest stash
5. Delete a Stash
Deletes a specific stash.
- Use
git stash drop <stash>
to delete the given<stash>
.
git stash drop
# Example
git stash drop stash@{1} # Deletes `stash@{1}`
6. Delete all Stash
Deletes all stashes.
- Use
git stash clear
to delete all stashes.
git stash clear
# Example
git stash clear
# Deletes all stashes
Congratulations!
And that’s the end of Git for Noob-to-Pro series 😃