Git

What Does `git stash push` Stash Do?

Developers make changes to their project source code files and move them to the staging index. Sometimes, they perform modifications but don’t want to push these changes into the Git repository. Additionally, they need to keep these changes temporarily. In such a situation, the “git stash push” command can be used.

This article will explain the working of the “git stash push” command.

What Does “git stash push” Stash Do?

To check the working of the “git stash push” command, try the following steps:

  • Move to the particular Git repository.
  • Check the list of the repository content.
  • Select and update the desired file.
  • Run the “git stash push” command to hold the temporary changes.

Step 1: Switch Git Repository

Use the “cd” command along with the required repository path and navigate to it:

$ cd "C:\Users\nazma\Git\test-repo"

Step 2: View List of Content

Now, execute the following command to display the repository content:

$ ls

Step 3: Open and Update Desired File

Then, run the “start” command to open and modify the particular file:

$ start

Step 4: Push Changes to Staging Index

To push the changes to the staging area, use the following command:

$ git add .

Step 5: Stash Changes

Next, temporarily hold the staged changes by running the “git stash push” command:

$ git stash push

Step 6: Show Stash List

Lastly, verify the stashed changes through the following command:

$ git stash list

It can be observed that the previously temporarily hold changes still exist in the list:

That’s all! We have explained the working of the “git stash push” command.

Conclusion

To view the working of the “git stash push” command, first, navigate to the particular Git repository and check the list of the repository content. Then, open and update the desired file. After that, save changes and execute the “git stash push” command to hold the temporary changes. This article elaborated on the working of the mentioned command.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.