Git Stash

What is Stash in Git,

In simple words, if i will try to explain stash, then it is nothing but temporarily remove/hide your existing changes and park it some secure place. So that you can pull code from git repository and apply(merge) these stashed(hidden) changes to latest code.

What we need to move-on with this article on git Stash

We will come to git, lets verify what we really need to get ready for Stash

Download and install git toll for Windows/Mac from here Download

After installing git your system, open Terminal or Command prompt and execute following command

git --version

It should return version above 2.0+

Your git version should be above version 2.0.

Different terminology that you should know before git stash

  • Tracked files – (Older files, which are already there in repository, you have not created yet)
  • Untracked files (Newer files, which are not there previously, you have added it)
  • unstaged files (Combination of modified Older files, new filed and deleted files)
  • staged files (Combination of modified Older files, new filed and deleted file)

What you should do before do any stash

  • If possible, stage you files, i mean (git add) command.
  • If you want to delete some existing file, do it, don’t hesitate
  • If you want to add some new file, do it, don’t hesitate

Different types of command and its meaning

Command -1: (If you have no untracked files or you have fired “git add” command already)

git stash

This will stash all tracked changes and files added to stage

Command -2: (If there are untracked files that need to be stashed with tracked files)

git stash -u

This will stash all your tracked file(old files) and untracked files(New files).

Command -3: (If you want to give a name to stash)

git stash save "stashNameGoesHere"

This is mainly required when you want to experiment with different types of code and give name to each type of changes, so in future you can roll back your code to required stash state.

Command -4: (see the list of available stash)

git stash list

Command -5: (Once you want to apply a stashed changes command to current Repo)

git stash apply


Usual process to use stash

git add *

git stash

git pull

git stash apply

git add *

git commit -m "your commit msg goes here"

git push origin "branchName"


Happy source code control :)