If you’re looking to learn how to stash your changes in Git, you’ve come to the right place. As α 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 α file in your Git repository, you would stage and then commit those changes.
GitTip: Not sure how to commit in Git? Test out our quick tutorial video before you get started with stashing.
But let’s say you’re in α situation where you’re in the middle of working on changes and are interrupted by α request to checkout α different branch, maybe to help α 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 α 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 α 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 đội nhóm members. However, it’s important to note: while stashing is useful for temporarily storing changes, stashing changes is not α 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 α feature branch checked out and are going to make α few edits to α file. But wait! You’ve just realized you meant to commit these changes on α different branch.
Before you stash your changes, let’s first type α 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 α ? 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.
You can also quickly see α danh mục of your stashes in the left panel.
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 danh sách.
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 sao chép in α clean state and allow you to run different commands, such asor Git pull.
If you wish to see the contents of your most recent stash, you can run:
git stash show
Git Stash Danh mục
But, what if you wanted to lượt xem the contents of an older stash? To do this, you will first have to run:
git stash danh mục
The Git stash danh mục command will pull up α danh mục of your repository’s stashes. Git will display all of your stashes and α corresponding stash index.
Now, if you wish to lượt xem the contents of α specific stash, you can run the Git stash show command followed by stash@ and the desired index.
git stash show stash@<indexvàgt;
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 α 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.