Home·Error messages

git · Git

The message

error: unable to unlink old 'dist/main.js': Permission denied

What it means

A checkout wanted to replace a file with a new version and the operating system refused to remove the old one. It happens when another program holds the file open, which is especially common on Windows, or when you do not have write permission on the directory. Close whatever holds it — dev server, editor, antivirus — and run the same command again; on Unix, fix the directory permission. Repeating the command is safe, but note that git stopped partway, so the working tree stays half-updated until it succeeds.

The fix

There is no one-line command for this. The explanation says what to look at instead.

Printed by
git
Git
29

Almost every git error is a refusal that means "doing that from this state would lose something"; fatal: means git stopped without changing anything, and the hint: lines under the first line usually carry the actual remedy.

Reading an error message

  • Read from the first line down. The lower you go the more it is about the tool’s internals; the cause is usually at the top.
  • If there is a file and a line number, start there — not the top stack frame, but the topmost line that names a file you wrote.
  • Search the message verbatim, but strip your own paths and variable names first; those are what stop the search from matching.
  • The same condition is worded differently across tool versions. If results look wrong, add the version number to the query.
  • Before pasting a fix, check what it throws away. Some of these cannot be undone.

Common questions

Q. What does “error: unable to unlink old 'dist/main.js': Permission denied” mean?

A checkout wanted to replace a file with a new version and the operating system refused to remove the old one. It happens when another program holds the file open, which is especially common on Windows, or when you do not have write permission on the directory. Close whatever holds it — dev server, editor, antivirus — and run the same command again; on Unix, fix the directory permission. Repeating the command is safe, but note that git stopped partway, so the working tree stays half-updated until it succeeds.

Q. How do I fix it?

There is no one-line command. The explanation above says what to look at instead.

Q. Which tool prints this?

git. It sits under Git, and the message runs to 8 words.

Errors nearby