92

New GIT user here, managing a Moodle course web site system on a Windows server. Trying to do my first Pull update of the core code (using TortoiseGit) and it's not working. Git is unable to unlink old versions of any the 200+ files to be updated because of an "invalid argument". I have no idea what that means.

Here's what it looks like after I dismiss 210 error dialogs: tortoisegit

I've rebooted the server and scoured the web for ideas, but I'm at a loss for what to try next.

Any ideas would be greatly appreciated!

pillsbur
  • 921
  • 1
  • 6
  • 3
  • 3
    Did you check this https://stackoverflow.com/questions/4452641/git-error-unable-to-unlink-old-some-file-name-bad-file-descriptor ? – mayo Jul 26 '17 at 19:42
  • 23
    On Windows when git complains about not being able to "unlink" a file, it's usually caused by another program holding the lock on the file preventing any other write access. Try stop the web server service, and close any other application you think might be related to these files. – jingx Jul 26 '17 at 19:47
  • I stopped the servers but got the same result: unable to unlink. Can't imagine what other program could be using the files if the web server isn't... – pillsbur Jul 27 '17 at 21:29
  • 2
    I had this on a Windows system too. Reboot of the system solved the issue. I think there was some orphan process keeping the file locked, but didn't have sufficient privileges to run Process Explorer in Administrator mode to hunt for it. – Jeroen Wiert Pluimers Aug 28 '17 at 11:07
  • for some reason explorer.exe likes to lock .csproj files after NuGet operations (update of existing package for example) are done. at least on my machine. Especially when I switch from a branch that has a newer version to a branch that has a (then) different version – Steffen Winkler Sep 13 '19 at 11:02

16 Answers16

214

I lost hours with that error too.

In my case, I got this error because some files was locked by another program. I had to close everything then I was able to pull again.

Hope this help someone :)

Nicolas Leucci
  • 2,829
  • 1
  • 13
  • 12
  • 4
    Thank you! That was my cause - some files were used by multiple 'JDK Platform Binary' instances and could not been updated. Solution for me was to manually close them all before branch checkout – ildar ishalin Feb 07 '19 at 12:00
  • 1
    In my case it was eclipse which locked the file. This answer is often the right solution – lynxSven Jul 10 '19 at 12:01
  • 1
    I had Excel open on a CSV that I was trying to update ... lesson learned! – Neil C. Obremski Nov 08 '19 at 15:53
  • 2
    Also, the locking program may be on another PC if your files are on a network drive. – thelr Feb 12 '20 at 17:58
  • I shut down Tomcat servers, then I exit Eclipse, and it worked. Thanks. – Berk Jul 28 '20 at 12:50
  • I closed PhpStorm and Vagrant. Still was getting the error. Then I checked TortoiseGit Commit popup was opened somewhere. I closed that also and tried again. The problem resolved!!! – aagjalpankaj Feb 10 '21 at 07:10
  • (Windows) If close a certain program (e.g. from its Close button) doesn't work, please check the Task Manager to make sure that whether its thread is still alive. – Jiang Dec 07 '21 at 06:15
  • In my case it was "git diff" with paging open in my terminal that was blocking the file. – Mehmet Karadeniz Oct 05 '22 at 06:58
49

The error message shows the file name(s) that git was unable to unlink. In windows, you can go to Start Menu > Resource Monitor > CPU tab > Associated Handles and search for the file name (not the full path), then you will get a result of the process locking that file. In my case, it was explorer.exe. So I killed that process and git worked again as expected.

I guess you can do that same using other operating systems by finding the process(es) locking the file(s).

Zein Makki
  • 29,485
  • 6
  • 52
  • 63
11

Try to close any other tools while using Tortoisegit

ColdFire
  • 1,301
  • 13
  • 14
10

I also had unlink issues when trying to pull from gitlab.

Based on ivan866's and Nicolas Leucci's answer, to resolve I simply opened my SourceTree in administrative mode which fixed my problem. I suppose SourceTree didn't have enough rights to handle the permissions correctly. Anyway it's worth a try!

Michael Manley
  • 131
  • 1
  • 6
7

The issue is connected with file permissions. Can appear after using the external drive on Windows 7, then on Windows 10 again. Especially it is risky to leave the first computer, i.e. the one used first, in hibernate mode with applications opened - many opened files can get corrupt after you reconnect the drive after using those files on another computer, but with same apps.
Can be healed with CHKDSK /f, but it is highly likely messed files will get deleted.

ivan866
  • 554
  • 4
  • 10
2

I rebooted the pc I was pulling the 'troubled' file into and at the same time I closed the IDE on my other pc which was using the very file and from which I had pushed it. It worked

2

I was running a program in InteliJ, and stopping it released the file. It worked afterwards

ymerdrengene
  • 1,421
  • 2
  • 17
  • 20
  • This worked for me with android studio as well. This means error can occur if some other application is holding a lock on file. So try closing such applications is a good idea. – Deshan Sep 13 '21 at 09:42
1

This issue happens if the solution is open in your IDE because the files are locked. Try to close the solution and then re-attempt the operation.

Ajay Meda
  • 313
  • 1
  • 11
1

For me, I was getting:

"error: unable to unlink old 'Library/ArtifactDB': Invalid argument error: unable to unlink old 'Library/SourceAssetDB': Invalid argument fatal: Could not reset index file to revision 'HEAD'."

And as soon as I closed Unity Git was able to work normally. I think the Unity permissions must've made it go funny.

0

I had this issue while merging branches. Opening Powershell with admin rights and performing merge there helped.

Alamakanambra
  • 5,845
  • 3
  • 36
  • 43
0

In my case, despite restarting my computer and closing any IDE I had running, I STILL had the problem, and trying to run the git pull in sudo mode returned a different error. The solution was tu use (in local, so it wasn't a security issue) sudo chmod 777 path/to/folder/of/file and sudo chmod 777 path/to/folder/of/file/specificFile.ext.

Jonathan Simonney
  • 585
  • 1
  • 11
  • 25
0

For me I had to close Unity. From now on I only use push/pull when Unity is closed.

Rob
  • 93
  • 3
0

I solved this problem by deleting the local file that git can't unlink it, and it worked fine

Ali_jaber
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 03 '22 at 16:26
0

If you are doing with terminal. Always Commit/Stash First so that you can hard reset to previous commits, to be able to take latest pull

0

In my case I added that folder for Windows Ransomware Protection and that locked the file and didn't allow the github to interact.

Sarmad Ali
  • 17
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 09 '23 at 16:56
-1

if you use WSL then use Git Bash instead

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34823300) – Yaroslavm Aug 15 '23 at 08:05