How to use git stash and git stash pop commands

Git helps to control the version of your projects. Git is a well-known software used by programmers to work in a collaborative manner to achieve specific goals. The Git repositories are hosted by GitHub that helps to work online and assist the programmers to share their project or code files there. Moreover, Git is backed up by several operations or commands also like Git stash, Git stash apply, Git stash pop, Git stash drop. Inspired by the importance of Git, today’s guide will provide fundamental information about Git stash and Git stash pop; and use of both commands/operations in Ubuntu.

So, let’s start this guide:

Git stash

Stashing is a phenomenon that is meant to temporarily store the files/content safely; Git also supports this feature, and it is recognized as “Git stash”. Programmers on Git frequently uses this feature Git stash allows you to store code or any text for later use: for instance, when you make changes to a file in your repository; it is possible you may encounter any other task, or you have to work on other project; so, you can commit those changes later on to save the original file.

Git stash pop

The Git stash pop is another useful command supported by Git; whenever you stash the content the next thing is you have to commit those changes at some stage. The Git stash apply is used to get the content from the stash file and commit it to the original file; there is another command Git stash drop that is used to drop the stash content without applying it. It is noticed that the functionalities of both commands can be performed by using a single command named as Git stash pop. This operation will get the content from the stash file and apply the changes to the file; moreover, alongside committing changes, it also drops the stash file.

How Git stash works in Ubuntu

Firstly, you must create Git project and initialize Git repository on your Ubuntu; you can create it locally by and the command mentioned below will create “newpro” project in your home directory:

$ git init --bare ~/newpro

Now, change the working directory of the terminal to “newpro” by using the command mentioned below:

$ cd /home/adnan/newpro

Keep your terminal in the same directory; keep in mind we are working for stash; for this purpose, we have to make changes to our project; we have created a python script by issuing the following command:

$ touch

Access this script using nano editor and write some text as a comment or you can write python code too:

$ nano

Execute the following command to initialize as well as embed changes to your Git project repository:

$ git init && git add .

Once the changes are added successfully, you must check the status of your repository by using the command mentioned below:

It is observed that the changes (that are not committed yet) are displayed in the output:

$ git status

After confirming that, the changes are not committed you can run the “Git stash” command to stash those changes; for that, execute the command in your Ubuntu terminal:

$ git stash

Lastly, once the changes are saved; you can again check the status to verify that changes have been sent to stash or not:

$ git status

How Git stash pop works in Ubuntu

Once stashing is performed, one can apply those changes save in stash: here we are popping the stash file with the help of “Git stash pop”. This will apply the changes as well as tunicates the stash file; before using pop we’ll execute the command mentioned below to display all the stash:

$ git stash show -p

After that, you can apply these changes and empty the stash file by using the command mentioned below:

$ git stash pop

Once you have popped the content, run the show stash command to verify either there is anything left or the content is applied and truncated:

$ git stash show -p


From the start of the 21st century, the computing era has been focused to make it technologically rich; especially the hardware and software evolution is the core achievement of this century. Another notable improvement is to work in a collaborative environment; this collaborative environment enables multiple programmers to work on a single project simultaneously and Git is the software that grants such permissions. In this article, we have briefly explained two basic commands of Git that are used to store and apply the uncommitted changes. Git stash helps to store the uncommitted content at a safe place whereas Git stash pop enables to apply the changes and truncate the associated stash file.

About the author

Adnan Shabbir