0

I have a pre-push script in .git/hooks that does the following:

git stash -u
<build / test>
git stash pop

However, if the working directory is clean, then git stash -u does nothing, and no stash is created. Then pop pops the previous stash item. Is there a way of forcing stash?

A workaround is to create a temp file, that I then delete to force there to be something to stash.

Staale
  • 27,254
  • 23
  • 66
  • 85
  • 1
    You cannot stash if there's nothing to stash. You can, however, check if there are any unstaged changes, as discussed [in this question](https://stackoverflow.com/a/3879077/7598462). – kowsky Feb 21 '18 at 11:34
  • You could check if `git stash -u` creates a new entry. – ElpieKay Feb 21 '18 at 11:52
  • I'm going to close as dup of https://stackoverflow.com/q/5737002/1256452 but note that since Git 2.9 there is also `git stash store`, which stores stashes created with `git stash create`. You can tell if `git stash create` created anything since it prints the hash ID; feed that to `git stash apply` to apply the stash. Note also `--keep-index` but note that there's a long standing bug with this. – torek Feb 21 '18 at 17:15

0 Answers0