pillsbur
pillsbur

Reputation: 1181

GIT pull failed: 'unable to unlink file: invalid argument'

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!

Upvotes: 118

Views: 150279

Answers (18)

ypbr
ypbr

Reputation: 226

I solved the issue by running Vs code as an administrator. I hope it should help someone (:

Upvotes: -1

Oracion
Oracion

Reputation: 103

It might be file being opened elsewhere (e.g. notepad). You can try using 'file locksmith' from PowerToys to find app using the file.

Upvotes: 2

Natalie Zhurbenko
Natalie Zhurbenko

Reputation: 1

if you use WSL then use Git Bash instead

Upvotes: -3

Sarmad Ali
Sarmad Ali

Reputation: 17

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

Upvotes: 0

Beatle Refractor
Beatle Refractor

Reputation: 659

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

Upvotes: 0

Ali_jaber
Ali_jaber

Reputation: 1

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

Upvotes: 0

Rob
Rob

Reputation: 107

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

Upvotes: 0

Vallisneria
Vallisneria

Reputation: 13

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.

Upvotes: 1

Ajay Meda
Ajay Meda

Reputation: 378

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.

Upvotes: 1

ymerdrengene
ymerdrengene

Reputation: 1421

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

Upvotes: 2

Jonathan Simonney
Jonathan Simonney

Reputation: 665

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.

Upvotes: 0

ColdFire
ColdFire

Reputation: 1431

Try to close any other tools while using Tortoisegit

Upvotes: 11

Zein Makki
Zein Makki

Reputation: 30052

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).

Upvotes: 52

Alamakanambra
Alamakanambra

Reputation: 7881

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

Upvotes: 0

Michael Manley
Michael Manley

Reputation: 131

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!

Upvotes: 10

fintechilla
fintechilla

Reputation: 21

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

Upvotes: 2

ivan866
ivan866

Reputation: 582

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.

Upvotes: 7

Nicolas Leucci
Nicolas Leucci

Reputation: 3359

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 :)

Upvotes: 265

Related Questions