UPGRADE TO GET UP TO 85% OFF GITKRAKEN PRO
Search
Close this search box.

What is Git Stash?

If you’re looking to learn how to stash your changes in Git, you’ve come to the right place. As a simple explanation, stashing allows you to save your file changes for later.

Stashing changes can be risky if you can’t find those changes later. GitKraken’s intuitive UI will ensure you always know where your stashed changes are.

Normally, when you edit, add, or delete a file in your Git repository, you would stage and then commit those changes. 

GitTip: Not sure how to commit in Git? Check out our quick tutorial video before you get started with stashing.

But let’s say you’re in a situation where you’re in the middle of working on changes and are interrupted by a request to checkout a different branch, maybe to help a colleague, but you’re not ready to commit your changes.

Or, maybe you discover you have the wrong branch checked out and the changes you’re working on actually need to be committed to another branch.

Here is where the Git stash command comes in. Creating a stash in Git saves uncommitted changes so you can work on other things in your repository without losing your work.

When you’re ready to reapply your changes, you will have the option to apply or pop your stash to your currently checked out branch.

What is Git stash apply?

Git stash apply will take the changes you have stored in a stash and apply them to the working directory of your currently checked out branch and will also keep the stash intact.

What is Git stash pop?

Git stash pop will also apply your stashed changes to the working directory of your currently checked out branch but will delete the stash after the changes have been applied.

How do you stash changes in Git?

Stashing changes in Git can be extremely helpful when you’re collaborating, giving you extra time to work on your changes without feeling rushed before you share them with team members. However, it’s important to note: while stashing is useful for temporarily storing changes, stashing changes is not a substitute for committing changes. Stashing in Git should be done in moderation; overusing this tool can make it hard to keep track of which saved changes are where.

We’re going to walk through how to stash changes using the powerful GitKraken Git GUI before reviewing how to Git stash in the command line.

Never lose track of your stashed changes again.

How do you stash changes with GitKraken?

In this example, let’s say you have a feature branch checked out and are going to make a few edits to a file. But wait! You’ve just realized you meant to commit these changes on a different branch.

Before you stash your changes, let’s first type a name into the WIP node. Now, when you click the Stash icon in the top toolbar, GitKraken will stash your changes with the name you’ve set.

Viewing Your Git Stashes in GitKraken

GitKraken’s UI was thoughtfully designed to provide as much visibility as possible, so you can clearly see what’s going on in your repositories. Tracking your stashed changes in GitKraken is easy and convenient; stashes are denoted with a 📥 icon so you can immediately distinguish them on your graph.

Clicking on the stash icon from the graph will allow you to see its saved contents in the commit panel on the right.

gitkraken making stash show contents in the right panel

You can also quickly see a list of your stashes in the left panel.

Stashes shown in the left panel of GitKraken

How do you Git stash apply with GitKraken?

If you wish to apply your stashed changes but keep the stash intact, you can right-click the stash from the central graph in GitKraken and select Apply Stash from the context menu.

How do you Git stash pop with GitKraken?

To pop your stashed changes in GitKraken, you will double-click your target branch—where you want your changes applied—to checkout that branch. Then you will simply hit Pop in the top toolbar. This will apply your stashed changes onto the correct branch and delete your stash. And from here, you can move forward with committing your changes.

Stash changes with less risk with GitKraken’s superior visual context.

How do you Git stash in the command line?

To stash uncommitted local changes in Git using the terminal, you will simply run the Git stash command. This will put your working copy in a clean state and allow you to run different commands, such as Git checkout or Git pull.

If you wish to see the contents of your most recent stash, you can run:

git stash show

Git Stash List

But, what if you wanted to view the contents of an older stash? To do this, you will first have to run:

git stash list

The Git stash list command will pull up a list of your repository’s stashes. Git will display all of your stashes and a corresponding stash index.

Now, if you wish to view the contents of a specific stash, you can run the Git stash show command followed by stash@ and the desired index.

git stash show stash@<index>

For the remainder of this article, we’re going to assume you’re working with your most recent stash, but you can always utilize this syntax with other Git stash commands as needed.

In this Git stash example, let’s say you stashed changes and then went on to finish other tasks in your repository. Now, how do you go about getting those stashed changes back? There are two paths to choose from to get your stashed changes back into your working repository.

How do you Git stash apply in the command line?

If you want to get your stashed changes back but want to keep the stash intact, you will use the Git stash apply command. This will take the changes of your most recent stash and apply them to your repository and preserve the stash.

git stash apply

How do you Git stash pop in the command line?

In the case that you wish to get your stashed changes back but do not want to keep your stash intact, you will instead use the Git stash pop command. Similar to Git stash apply, Git stash pop will apply your most recent stash to your repository but will remove the contents of the latest stash for you afterwards.

git stash pop

Ready for a cleaner way to Git stash?

GitKraken’s intuitive UI makes tracking the stashes in your repository ridiculously easy by denoting each stash with an icon in the central graph, no need to find or remember stash indexes.

Never lose track of stashed changes again. Download the legendary cross-platform GitKraken Git client for Windows, Mac, & Linux.

Additional Resources

Table of Contents

Visual Studio Code is required to install GitLens.

Don’t have Visual Studio Code? Get it now.

Team Collaboration Services

Secure cloud-backed services that span across all products in the DevEx platform to keep your workflows connected across projects, repos, and team members
Launchpad – All your PRs, issues, & tasks in one spot to kick off a focused, unblocked day. Code Suggest – Real code suggestions anywhere in your project, as simple as in Google Docs. Cloud Patches – Speed up PR reviews by enabling early collaboration on work-in-progress. Workspaces – Group & sync repos to simplify multi-repo actions, & get new devs coding faster. DORA Insights – Data-driven code insights to track & improve development velocity. Security & Admin – Easily set up SSO, manage access, & streamline IdP integrations.
winget install gitkraken.cli