How to fix the "unlink of file failed" error in Git?

Tim Mouskhelichvili
Tim Mouskhelichvili
• 2 minutes to read

Sometimes, when you try to change branches or pull the most recent changes in Git, you get an "unlink of file failed" error. But what is this strange error, and how do you fix it?

This article explores why this error happens and shows a list of methods that will help you solve this error.

Let's get to it 😎.

git unlink of file failed

Why does this error happen?

The "unlink of file failed" Git error happens when another program uses the same file AND prevents Git from moving the file in/out of your working directory.

To fix this error, go down this list of potential fixes till you find the one that fixes your case.

Fix #1 - Close any application that might use the file in question.

Close your IDE (Eclipse, Visual Studio Code, IntelliJ) or any other application that might use the file in question, AND re-run the command that gave you the error.

Fix #2 - Run the garbage collector.

Run the Git garbage collector to remove temporary and unnecessary files, like so:

bashgit gc

After, re-run the command that gave you the error.

Fix #3 - Run Git with administrator privileges (Windows only)

Running Git from a command line with administrator privileges might fix this error.

Fix #4 - Enable the long path support flag (Windows only)

If your path is very long, you might need to enable long path support in your Git global configuration, like so:

bashgit config --global core.longpaths true

Then, re-run the command that gave you the error.

Final thoughts

As you can see, fixing the "unlink of file failed" Git error is easy.

Most of the time, you simply need to restart your IDE and run the git gc command.

git unlink of file failed

Here are some other Git tutorials for you to enjoy:

Comments (0)
Reply to: