Dreamcatcher
Dreamcatcher

Reputation: 828

git-stash cannot be used without a working tree error

I use git 2.7.2.windows.1. I encounter "C:\Program Files\Git\mingw64/libexec/git-core\git-stash cannot be used without a working tree." when I try to use git-stash command.

git worktree list command output:

E:/Git Repositories/test-desktop-client  63bb5ca [master]

How can I resolve this problem?

Upvotes: 3

Views: 3701

Answers (2)

mvanle
mvanle

Reputation: 2005

Try:

$ git --work-tree=. stash

Upvotes: 2

VonC
VonC

Reputation: 1323403

If you are in a recent git worktree (as in "managing multiple wroking tree") and stash, for some reason, does not work, you can use an additional worktree as an alternative to stashing:

You are in the middle of a refactoring session and your boss comes in and demands that you fix something immediately.
You might typically use git stash to store your changes away temporarily, however, your working tree is in such a state of disarray (with new, moved, and removed files, and other bits and pieces strewn around) that you don’t want to risk disturbing any of it.
Instead, you create a temporary linked working tree to make the emergency fix, remove it when done, and then resume your earlier refactoring session.

$ git worktree add -b emergency-fix ../temp master
$ pushd ../temp
# ... hack hack hack ...
$ git commit -a -m 'emergency fix for boss'
$ popd
$ rm -rf ../temp
$ git worktree prune

That being said, git stash should work in a git worktree.
Start by checking if git config core.bare is false.

Upvotes: 1

Related Questions