YavarTechWorks
Published in

YavarTechWorks

Git for Noob-to-Pro — #5(Stash)

If you don’t have time to read but want to know what’s there in this series. Find the quick read 👇

A quick read about this series

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

  1. Local Repository
  2. Branches
  3. Commits
  4. Module
  5. Stash

On this Post

In this post, we are going to see the topic Stash which has the following sub-topics like

  1. Create a Stash
  2. List all stashes
  3. Apply a Stash
  4. Apply the latest Stash
  5. Delete a Stash
  6. Delete all Stashes
A quick read about Git Stash

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] [<message>]# 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 <stash># 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 <stash># Examplegit 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 <stash># Examplegit 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# Examplegit stash clear
# Deletes all stashes

Congratulations!

And that’s the end of Git for Noob-to-Pro series 😃

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nidhin kumar

Nidhin kumar

502 Followers

As a species, we have an inbuilt need to connect with others to communicate and share.