Cloude Devops Logo Free Clss Will start on Devops from July 15th
Cloud DevOps
Cloud DevOps

Git Stash

DevOps Tutorial

Working with Stash

Git allows multiple users to work on the same project simultaneously. Suppose if a developer is working on a feature in a branch and he needs to pull changes from some other developer's branch or if he has to work urgently on some other feature, but the feature he is currently working on is incomplete. In this case, you cannot commit the partial code of the currently working feature. To add this new feature, you have to remove your current changes and store them somewhere else. For this type of situation, Git offers a very useful command known as 'git stash'.

DevOps Tutorial

git stash command saves the previously written code and then goes back to the last commit for a fresh start. Now you can add the new feature without disturbing the old one as it is saved locally. After committing the new feature you can go on with working on the old feature which was incomplete and uncommitted.

The git stash command is probably one of the most powerful commands in Git.

Git stash is used in order to save all the changes done to the current working directory and to go back to the last commit done on the branch (also called HEAD).

Stashing changes comes with a special set of Git commands designed to create, delete and apply stashes at will.

In this tutorial, we are going to learn about about git stash commands and how they can be used in practical cases.

Table of Contents

Git stash List

Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. ... A stash is by default listed as "WIP on branchname … ​", but you can give a more descriptive message on the command line when you create one. At this point, you can switch branches and do work elsewhere; your changes are stored on your stack. To see which stashes you've stored, you can use git stash list:

$ git stash list 
DevOps Tutorial

By git stash list command we can see if any files in the git stash memory. Note:- Can't see in file format in stash memory by git stash list.

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)

$ git stash list

⇒ In above practical... there are no any files inside stash memory.

⇒ check by git status command for files are in the working tree or not.

DevOps Tutorial

Yes files are in the working. We are seeing green and red color files in above screenshot.

If files are not available in working tree ...! No chance to send into the stash location.

If you don't have any files in side working tree...! Create the / keep the files inside working tree. (Working directory + Staging area)

Now going to step 3.

Create a Git stash

The easiest way to create a git stash is to simply run the "git stash" command without any parameters.

Now I am creating git stash.. Please fallow the bellow steps. ⇒

$ git stash    
↪  command used for to send the files from working tree to stash location. 

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)

$ git stash
Saved working directory and index state WIP on master: e8023c9 Test Commit

As you can see, my working directory as well as my index was saved for the "aws-devops" which is the current name of my branch.

For practical... fallow the bellow screenshot DevOps Tutorial

Now see the stash memory by git stash list command

$ git stash list

stash@{0}: WIP on master: e8023c9 Test Commit  is the id of stash. 

Note:- Can't see in file format in stash memory by git stash list. We can see only in stash id  format. 
For practical example: please have a look on bellow screenshot DevOps Tutorial

please have a look on git stash id after applying git stash list in the bottom of the above screenshot

now see the files are available or not in working tree by git status and ls -l or ll

See the fallowing screenshot

DevOps Tutorial

As a consequence, all the changes staged for commit in your current working directory will be saved on the side for later use.

After the colons, you can see the hash of the HEAD commit as well as the commit message : this is the name of your stash.

In this case, no names were assigned to our stash which might not be very handy if you want to pop your stash later on.

Create a Git stash with a name

In order to create a git stash with a name, use the "save" command and specify the name of your stash.

$ git stash save "my_stash_name" 

Back to the example we gave before on the branch named "aws-devops", we would run

$ git stash save "modified aws"

See the fallowing screenshot

DevOps Tutorial

$ git stash save "cloud_devops"
Saved working directory and index state On master: cloud_devops

there are no any files in working tree after applying git stash save command.

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ git status
On branch master
nothing to commit, working tree clean

command to see stash id in the stash memory
Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ git stash list
stash@{0}: On master: cloud_devops

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)

Now, Git did not provide a default name (made by the last HEAD commit message) but it assigned a custom name to it.

Alternatively, you can use the "git stash push" command in order to create a stash with a name.

$ git stash push -m "modified the aws" again
Saved working directory and index state On aws-devops: modified again the READ.me 

Stash a specific file

Using the previous commands, you have stashed all the tracked files in your current working directory.

In some cases, you may want to stash a specific file in order to retrieve it later on.

To stash a specific file, use the "git stash push" command and specify the file you want to stash.

$ git stash push -m "message" <file> 
DevOps Tutorial

For example, in order to stash the "aws" file in our current working directory but keep changes done to the other files, we would run

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)

$ git status
On branch master
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
        modified:   aws

no changes added to commit (use "git add" and/or "git commit -a")

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ ll
total 1
-rw-r--r-- 1 Cloud DevOps 197121 49 Aug  4 10:38 aws

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
                                                      
$ git stash list
stash@{0}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ git stash push -m "modified the aws " aws
Saved working directory and index state On master: modified the aws

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ git status
On branch master
nothing to commit, working tree clean

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$

However, the other tracked files that may be modified in your current working directory are untouched.

Stash untracked files

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master) $ ll total 0 -rw-r--r-- 1 Cloud DevOps 197121 0 Aug 4 10:38 aws Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)

$ git status
On branch master
nothing to commit, working tree clean

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ touch python corejava aws-devos azure-devops python-in-devops

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ git status
On branch master
Untracked files:
  (use "git add ..." to include in what will be committed)
        aws-devos
        azure-devops
        corejava
        python
        python-in-devops

nothing added to commit but untracked files present (use "git add" to track)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ DevOps Tutorial

As you probably noticed before when creating stashes, stash only saves tracked files of your working directory by default.

But what if you wanted to stash untracked files of your current working directory?

In order to stash untracked files, add the "-include-untracked" option to your "git stash" initial command.

Alternatively, you can simply use the "-u" which is equivalent to the untracked longer version.

$ git stash --include-untracked Saved working directory and index state WIP on aws-devops: 808b598 Initial commit DevOps Tutorial

$ git stash -u 


Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ git status
On branch master
nothing to commit, working tree clean

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$ touch ansible-on-linux docker-on-linux chef-on-centos

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)

$ git status
On branch master
Untracked files:
  (use "git add ..." to include in what will be committed)
        ansible-on-linux
        chef-on-centos
        docker-on-linux

nothing added to commit but untracked files present (use "git add" to track)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)

$ git stash -u
Saved working directory and index state WIP on master: e8023c9 Test Commit
DevOps Tutorial


Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)

$ git status
On branch master
nothing to commit, working tree clean

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)

$ git stash list
stash@{0}: WIP on master: e8023c9 Test Commit
stash@{1}: WIP on master: e8023c9 Test Commit
stash@{2}: On master: modified the aws
stash@{3}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (master)
$

Stash in a specific branch

DevOps Tutorial

In some cases, you may want to stash your current changes into a specific branch.

DevOps Tutorial

Let's say for example that you worked on the "master" branch for modifications, but you decide that your work may need a specific branch for integration.

This can be done with the "git stash branch" command.

$ git stash branch <branch_name> DevOps Tutorial

$ git stash branch <branch_name> stash@{stash_index}

Let's say for example that you want to stash your current changes in a branch named "aws-devops", you would execute.

$ git stash branch aws-devops stash@{0}
DevOps Tutorial


Switched to a new branch 'aws-devops'
On branch branch5
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   aws

no changes added to commit (use "git add" and/or "git commit -a")
Dropped stash@{0} (8bf64dd0e0045069bf3b3e7d9e34f5e5227aefa7) 

As you can see, the stash is dropped at the end of the process, essentially removing it completely from the stash stack.

List Git stashes

for example:

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git status
On branch aws-devops
Untracked files:
  (use "git add ..." to include in what will be committed)
        aws-devos
        azure-devops
        chef-on-centos
        corejava
        docker-on-linux
        python
        python-in-devops

nothing added to commit but untracked files present (use "git add" to track)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git stash -u
Saved working directory and index state WIP on aws-devops: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git status
On branch aws-devops
nothing to commit, working tree clean

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: On aws-devops: ansible
stash@{3}: On aws-devops: ansible
stash@{4}: WIP on master: e8023c9 Test Commit


Now that you have created some stashes, it is time for you to list the stashes that you just created.

In order to list Git stashes, use the "git stash list" command.

$ git stash list

stash@{0}: WIP on aws-devops: 808b598 Initial commit
stash@{1}: On aws-devops: modified aws
stash@{2}: On aws-devops: modified again the READ.me 
DevOps Tutorial

As you can see, stashes are given an index starting at zero.

When creating new stashes, items are added to the stack meaning that the most recent stash has the index 0 while the oldest stash is at the bottom of the stack.

This is closely related to the concept of stack in software engineering. A link to an in-depth article is included if you are curious about stacks.

Apply Git stashes

Now that you have saved your Git stashes on the side, you might want to "take them out from the stack" and apply them to your current working directory.

In order to apply your Git stash to your current working directory, use the "git stash apply"command and specify the stash you want to apply.

If you don't specify any arguments to the apply command, the top of the stack will be applied.

$ git stash apply stash@{stash_index}

$ git stash apply (shortcut for git stash apply stash@{0}) 
for example:

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: On aws-devops: ansible
stash@{5}: On aws-devops: ansible
stash@{6}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash apply
On branch aws-devops
Changes to be committed:
  (use "git restore --staged ..." to unstage)
        new file:   ansible-playbooks

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
        modified:   aws

for example:-

DevOps Tutorial Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: On aws-devops: ansible
stash@{5}: On aws-devops: ansible
stash@{6}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$

For example, in order to apply the changes done in the stash with the index 1, we would run

$ git stash apply stash@{1}

Already up to date!
On branch aws-devops
Your branch is up to date with 'origin/aws-devops'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   aws

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        file 

By default, the stash apply command will list your current working directory after apply the corresponding stashes.

Now if you were to list your stashes, you would notice that applying your stash did not delete or remove the stash from the list.

$ git stash list

stash@{0}: WIP on aws-devops: 808b598 Initial commit
stash@{1}: On aws-devops: modified aws
stash@{2}: On aws-devops: modified again the READ.me 

If you want your stashes to be removed after applying them, you need to use the "git stash pop" command.

Pop Git stashes

DevOps Tutorial

So what is the difference between git stash pop and git stash apply?

The main difference is in the fact that the "git stash pop" applies your changes to your current working directory but it also deletes the stash from the stash stack.

To pop Git stashes, simply use the "git stash pop" command and specify the stash index you want to pop.

For Example:

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git status
On branch aws-devops
nothing to commit, working tree clean

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: WIP on aws-devops: e8023c9 Test Commit
stash@{5}: WIP on aws-devops: e8023c9 Test Commit
stash@{6}: WIP on aws-devops: e8023c9 Test Commit
stash@{7}: On aws-devops: ansible
stash@{8}: On aws-devops: ansible
stash@{9}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash pop
Already up to date!
On branch aws-devops
Untracked files:
  (use "git add ..." to include in what will be committed)
        aws-devos
        azure-devops
        chef-on-centos
        corejava
        docker-on-linux
        python
        python-in-devops

nothing added to commit but untracked files present (use "git add" to track)
Dropped refs/stash@{0} (b238f488664f8fc693d6bb9b461a3708bc4394ed)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$
DevOps Tutorial
$ git stash pop stash@{stash_index} 
Back to our previous stash example, this would give us Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
                                                      
$ git status
On branch aws-devops
nothing to commit, working tree clean

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: WIP on aws-devops: e8023c9 Test Commit
stash@{5}: WIP on aws-devops: e8023c9 Test Commit
stash@{6}: WIP on aws-devops: e8023c9 Test Commit
stash@{7}: On aws-devops: ansible
stash@{8}: On aws-devops: ansible
stash@{9}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash pop stash@{3}
On branch aws-devops
Changes to be committed:
  (use "git restore --staged ..." to unstage)
        new file:   ansible-playbooks

Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git restore ..." to discard changes in working directory)
        modified:   aws

Dropped stash@{3} (4cd54b77e02ab6e20db6a569da666fa0905fcd74)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$

For Practical Example

DevOps Tutorial

See the difference in the last line of the example?

The stash was dropped and removed from the stack.

Show Git stash differences

When you create a stash, it is most likely to perform some commits before going back to your stashed content.

As a consequence, you may want to see the differences between your stash and the most recent commit of your branch (also called HEAD)

To show differences between a stash and the most recent commit, use the "git stash show" command.

$ Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: WIP on aws-devops: e8023c9 Test Commit
stash@{5}: WIP on aws-devops: e8023c9 Test Commit
stash@{6}: On aws-devops: ansible
stash@{7}: On aws-devops: ansible
stash@{8}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash show stash@{6}
 ansible-on-linux  | 0
 ansible-playbooks | 0
 ansible-roles     | 0
 3 files changed, 0 insertions(+), 0 deletions(-)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash show stash@{8}
 ansible | 1 +
 aws     | 1 +
 chef    | 0
 devops  | 0
 docker  | 0
 git     | 0
 linux   | 0
 7 files changed, 2 insertions(+)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
 

for practical

DevOps Tutorial

As a consequence, you will be listed with the differences between files, the insertions and the deletions done.

To see all the differences including content, add the "-p" option.

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: WIP on aws-devops: e8023c9 Test Commit
stash@{5}: WIP on aws-devops: e8023c9 Test Commit
stash@{6}: On aws-devops: ansible
stash@{7}: On aws-devops: ansible
stash@{8}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash show -p stash@{5}
diff --git a/ansible-playbooks b/ansible-playbooks
new file mode 100644
index 0000000..e69de29
diff --git a/aws b/aws
index e69de29..95302dd 100644
--- a/aws
+++ b/aws
@@ -0,0 +1,2 @@
+Hi
+aws is a complete public service provider.

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$

For Practical Example

DevOps Tutorial

Drop Git stashes

In some cases, you may want to delete a Git stash entry from your stack.

In order to drop stashes, you have two options : with drop or clear.

If you want to drop a specify stash from your stack, use the drop option and specify the stash index.

by Default git stash drop command

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: WIP on aws-devops: e8023c9 Test Commit
stash@{5}: WIP on aws-devops: e8023c9 Test Commit
stash@{6}: On aws-devops: ansible
stash@{7}: On aws-devops: ansible
stash@{8}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash drop
Dropped refs/stash@{0} (755dd3845324a47cb280dcdbd4f2794968faca3b)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: WIP on aws-devops: e8023c9 Test Commit
stash@{5}: On aws-devops: ansible
stash@{6}: On aws-devops: ansible
stash@{7}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$

by Droping the Stash on Partcular ID's

$ git stash drop stash@{stash_index} 
DevOps Tutorial

For example, in order to delete stash with an index 1 from the previous example, you would run

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: WIP on aws-devops: e8023c9 Test Commit
stash@{5}: On aws-devops: ansible
stash@{6}: On aws-devops: ansible
stash@{7}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash drop stash@{6}

Dropped stash@{6} (325e9258244d767fb6ca1f419f660f34989f3141)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: WIP on aws-devops: e8023c9 Test Commit
stash@{5}: On aws-devops: ansible
stash@{6}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash drop stash@{2}
Dropped stash@{2} (cce1211f3fc98e5c4575036fa23baf5669e3e2dc)

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: On aws-devops: ansible
stash@{5}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
 

Drop all stashes using clear

If you want to delete all the Git stashes in your stack, you have to use the clear command.

$ Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)

$ git stash list
stash@{0}: WIP on aws-devops: e8023c9 Test Commit
stash@{1}: WIP on aws-devops: e8023c9 Test Commit
stash@{2}: WIP on aws-devops: e8023c9 Test Commit
stash@{3}: WIP on aws-devops: e8023c9 Test Commit
stash@{4}: On aws-devops: ansible
stash@{5}: WIP on master: e8023c9 Test Commit

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash clear
Make sure that all your stashes were deleted with the list command.
Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$ git stash list

Cloud DevOps@DESKTOP-T1B0O13 MINGW64 /d/Git Projects/demo_repo (aws-devops)
$

For Practical example

DevOps Tutorial

Conclusion

In this tutorial, you learnt about git stash : how you can create stashes, delete stashes, and pop them in order to recover your work.

Git stash is pretty useful, but there are many other commands that you may find useful when using Git :

  • You can learn how to set the upstream branch on Git;
  • If you are just starting out, you can start by cloning repositories into your system.

If you are interested in software engineering, we have a complete section dedicated to it on the website, so make sure to check it out!












The DevOps seminar will help you to learn DevOps from scracth to deep knowledge of various DevOps tools such as fallowing List.

Linux, Git, Jenkins, Maven, Apache Tomcat, Nexus, Ansible, Chef, MySQL Docker, Nagios,   Kubernetes.
Continue to Next

Automation