From what I read, it looks like the git stash command stores its information in the local repo and not inthe remote repo. My concern is that this is vulnerable to loss due hardware failure for each dev. Especially, if devs stash changes for a longer duration. Any best practices other than limiting duration of stashes?
-
1Almost all `git` sub-commands, except `fetch`, `push`, `pull`, `clone`, and `remote`, operate only within your local repo... – twalberg Sep 02 '14 at 20:36
-
Each stashed entry *is* a commit—or rather, at least two and sometimes three commits. See my diagram in my answer to [git stash and apply](http://stackoverflow.com/q/20409853/1256452). It's therefore possible to push or clone it, but it won't be pushed or cloned by default because `refs/stash` is not in the usual push/clone name-space. – torek Sep 03 '14 at 01:14
3 Answers
That's right.
Stash is used (in common) for some non finished changes which is hard to be even packed into a commit. For changes that need to be shared with another git client via remote there are branches which are just a named reference to a particular commit. Also people of uses some -experimental
branches (both local and remote) for something that may look not very usable in the current state but could be helpful later.
Any best practices other than limiting duration of stashes?
There are no any logical limitation for a stash to be lived a long time. But remember, stash will become hardly to use when all files that were changed in it will be hardly modified. It will be almost impossible to pop it back because of huge number of conflicts.

- 21,474
- 11
- 78
- 131
You are right, when git stash
is executed it's saved in local repo. Git is very versatile and I won't be surprised to learn that there is a way to push local stash to remote repo I won't even bother googling it, I don't think stash is a good thing to exist.
Stashes are very handy in various cases (switching branches, checking functionality pre-changes etc) however I would recommend to pop
/apply
stash as soon as possible, usually I try not to keep stashes for longer than hour, and I will always clear my stashes before I leave my laptop for extended period of time (end of work day, lunch whatever). I would say that if something is important enough to be pushed or saved for longer than hour, it's probably important enough to have it's branch. Thank Git to have such a versatile branching system :)

- 364
- 1
- 3
- 18
I'd say the best practice is to back up your local Git repo just like you should back up your local documents or other files.

- 19,940
- 10
- 72
- 93
-
We avoid use of local anything - everything is in some corporate system such as Confluence, JIRA, Git, SVN, etc, which is of course backed up. – halt00 Sep 02 '14 at 21:03
-
What about users' working directories before they've committed their changes to Git? Same issue. – Matthew Strawbridge Sep 03 '14 at 11:10
-
Agreed, but the problem we have been seeing is that something get stashed and then forgotten (on purpose - e.g. postponed, or really forgotten). – halt00 Sep 03 '14 at 20:59