Git Stash – How to Stash Changes in Git | Learn Git – GitKraken

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

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

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

But let’s say you’re in a situation where you’re working on changes and you’re interrupted by a request to review a different branch, perhaps to help a colleague, but you’re not ready to confirm your changes.

Or maybe you find that you have the wrong branch checked and the changes you’re working on really need to be confirmed in another branch.

This 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 are ready to reapply the changes, you will have the option to apply or place your stash in your currently retired 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 retired branch and also keep the stash intact.

What is Git stash pop?

Git stash pop will also apply the hidden changes to the working directory of the currently retired branch, but will delete the stash after the changes have been applied.

How are changes saved in Git?

Saving changes to

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

Let’s see how to hide changes using the powerful GitKraken Git GUI before reviewing how to hide Git on the command line.

How do I save changes with GitKraken?

In this example, suppose you have an unprotected feature branch and you are going to make some edits to a file. But wait! You just realized that you wanted to make these changes in a different branch.

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

View your Git caches

on GitKraken

GitKraken’s user interface was carefully designed to provide as much visibility as possible, so you can clearly see what’s happening in your repositories. Tracking your hidden changes on GitKraken is easy and convenient; The caches are indicated with an 📥 icon so that you can immediately distinguish them on your chart.

By clicking on the stash icon of the chart, you will be able to see its saved content in the confirmation panel on the right.

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

How is Git stash applied with GitKraken?

If you want to apply your saved changes but keep the stash intact, you can right-click on the stash from the middle chart on GitKraken and select Apply Stash from the context menu.

How do you do Git stash pop with GitKraken?

To show your hidden changes on GitKraken, double-click your target branch, where you want your changes to be applied, to check out that branch. Then you will simply press Pop on the top toolbar. This will apply the hidden changes to the correct branch and delete your stash. And from here, you can go ahead with confirming your changes.

How do I hide Git on the command line?

To save uncommitted local changes to 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 want to see the contents of your most recent stash, you can run: git stash show

Git Stash List

But what if

you want to see the contents of

a previous stash? To do this, you will first need to run:

Git cache list The Git cache list command will display a list of your repository’s hiding places. Git will display all your caches and a corresponding stash index.

Now, if you want 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 rest of this article, we’re going to assume you’re working with your latest stash, but you can always use this syntax with other

Git stash commands as needed.

In this Git stash example, let’s say you hid the changes and then finished other tasks in your repository. Now, how do you go about recovering those hidden changes? There are two paths to choose from to get your hidden changes back into your working repository.

How do I apply Git stash on the command line?

If you want to recover your hidden changes but want to keep the stash intact, you’ll use the Git stash apply command. This will take the changes from your most recent stash and apply them to your repository and preserve the stash.

Git stash application How do you do Git stash pop

on the command line?

In the event that you want to retrieve your saved changes but don’t want to keep your stash intact, you’ll use the Git stash pop command. Similar to Git stash apply, Git stash pop will apply your most recent stash to your repository, but delete the contents of the last stash for you later.

Git stash pop

Ready for a cleaner form of Git stash?

GitKraken’s intuitive user interface makes tracking the caches in your repository ridiculously easy by denoting each stash with an icon in the center graph, without needing to find or remember stash indexes

.

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