The problem
On Windows, git stash may report unable to unlink when it cannot replace or remove a working-tree file. A running program may have the file open, but permissions, antivirus scanning, or another filesystem issue can also prevent the operation. The message alone does not identify the cause.
Recover without moving repository files
- Read the complete Git error and note each affected path. Do not move or delete the repository contents as a workaround.
- Close the application that may be using the affected file, such as the program being built or a process launched from that folder.
- On Windows, use Microsoft Sysinternals Process Explorer (Find Handle or DLL) or Handle to identify a process with the path open. Close that application normally; avoid forcibly closing an individual handle.
- Check that the intended changes are still present with
git status. If needed, save a separate backup before retrying. - Retry
git stash push -uto include untracked files. If it still fails, record the exact path and error and investigate permissions, filesystem health, or security software instead of repeatedly retrying.
What the stash option does
-u includes untracked files in the stash. It does not fix an operating-system lock or permission error. Git stash does not include ignored files unless you use -a; check the Git stash documentation before choosing that option.
Prevention
- Stop programs that are using files before switching branches or stashing.
- Keep generated build outputs out of version control when appropriate, using a project-specific
.gitignore. - Review
git statusand preserve any uncommitted work before recovery steps.
Technical Details
The error commonly occurs with:
- Build output files (
.dll,.exe,.pdb) - Configuration files (
appsettings.json) - Referenced assemblies in the
refs/directory
This is particularly common in .NET Core applications where the build process generates multiple interdependent files.