Getting to grips with git – the stash, working directory, index, local repo, remote repo

When starting git it’s really helpful to know there are a bunch of locations your source can exist. These are the:

  •  stash
  • working directory
  • index
  • local repo
  • remote repo

I don’t know if this cheat sheet helps or just overwhelms but some may find it useful:


git stash

The docs say:

git-stash - Stash the changes in a dirty working directory away

but there are plenty of ambiguities here.


What exactly does stash mean?

And what’s a dirty working directory?

Say you’ve got this:

On branch master
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

	modified:   A

Untracked files:
  (use "git add ..." to include in what will be committed)


in your current directory your gut reaction might be that it will store your changes to both A and B. After all you’ve changed both and they’re both in your working directory.

That’s not the case:

git stash
Saved working directory and index state WIP on master: 2236ca9 with A
On branch master
Untracked files:
  (use "git add ..." to include in what will be committed)


nothing added to commit but untracked files present (use "git add" to track)

B is ignored. You need to add it to the repo to stash it.

To stash B, use git stash -u


Note: a dirty working directory would seem to indicate a changed file in the current working directory. It isn’t.

dirty state means modified tracked files and staged changes

working directory is a repository created with the git init command.


Useful discussions:


View stash

List stashes with:

git stash list

View contents of stash with:

git stash show -p stash@{0}


Apply stash

Apply stash with:

git stash apply stash@{0}

Note that this won’t remove the stash from the list.


If you attempt to stash it again, you’ll just add another identical entry into your stash list.

To remove it from the list use:

git stash drop stash@{0}


Leave a Reply

Your email address will not be published. Required fields are marked *