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

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-use-git-stash-and-git-stash-pop-commands-1.png" data-lazy- height="61" src="data:image/svg xml,” width=”615″>

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

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-use-git-stash-and-git-stash-pop-commands-2.png" data-lazy- height="48" src="data:image/svg xml,” width=”633″>

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

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-use-git-stash-and-git-stash-pop-commands-3.png" data-lazy- height="99" src="data:image/svg xml,” width=”724″>

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

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-use-git-stash-and-git-stash-pop-commands-4.png" data-lazy- height="66" src="data:image/svg xml,” width=”724″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-use-git-stash-and-git-stash-pop-commands-5.png" data-lazy- height="136" src="data:image/svg xml,” width=”623″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-use-git-stash-and-git-stash-pop-commands-6.png" data-lazy- height="72" src="data:image/svg xml,” width=”716″>

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

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-use-git-stash-and-git-stash-pop-commands-7.png" data-lazy- height="115" src="data:image/svg xml,” width=”722″>

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-use-git-stash-and-git-stash-pop-commands-8.png" data-lazy- height="164" src="data:image/svg xml,” width=”635″>

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

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:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/How-to-use-git-stash-and-git-stash-pop-commands-9.png" data-lazy- height="197" src="data:image/svg xml,” width=”680″>

Conclusion

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.