# Git Stash - Saving Your Changes

DevFeed: [Git Stash - Saving Your Changes](<https://devfeed.tech/articles/git-stash-saving-your-changes-24934.md>)

Original publisher: [Read original article](<https://codeahoy.com/2016/04/18/10-git-stash-explained/>)

Author: umer

Published: 2016-04-18T00:00:00Z

Content type: tutorial

Language: en

Sources: [Code Ahoy - Articles](<https://devfeed.tech/sources/code-ahoy-articles.md>)

Topics: [Git](<https://devfeed.tech/topics/git.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [git](<https://devfeed.tech/tags/git.md>), [how-to](<https://devfeed.tech/tags/how-to.md>)

## AI overview

A tutorial explaining how Git stash temporarily saves tracked and staged changes so developers can switch branches or address urgent work, then reapply the saved changes later. It also covers listing multiple stashes and handling merge conflicts.

## Source excerpt

Let's say you are in the middle of implementing a new feature. You're half way through your changes and the code is in a messy state. You get a message that there's an urgent issue that requires you to switch gears and work on it immediately. You don't want to commit your half baked changes but also don't want to lose your work because you want to revisit it at a later time? What do you do? The answer to this problem is the git stash command. Running git stash will take the changes you've made to tracked files in the working directory as well as staged changes and saves them to a stack. You can reapply these changes from the stack at any time. After stashing, you'll end up with a clean working directory and can freely switch branches and work on something else. Let's walk through a complete example. Let's say we're in the middle of editing file.txt when we get a Slack message to switch to something else right away. We'll use git stash to save our changes. $ echo "Improvement 1 of 3" >> file.txt $ git status On branch master Your branch is ahead of 'origin/master' by 1 commit. modified: file.txt $ git stash save "Partial improvement to file.txt" $ git status # On branch master nothing to commit, working directory clean After stashing, you're free to do whatever you like. You can switch to a different branch, make your changes, commit and push them to the remote repo. After you're done, you're ready to resume working on file.txt which you stashed away. To reapply, you will use the git stash apply command. $ git stash apply Assuming you don't run into merge issues, you should get your partial changes back. If not, git will throw a merge conflict error if it can't reapply your changes safely. We'll look at how to resolve merge conflicts in the next chapter. You can stash multiple times. Each time you run git stash it will save a new stash on the stack. To see a list of all the stashes stored on the stack, use the git stash list command. $ git stash list stash@{0}: WIP o