Paul
Paul

Reputation: 982

Cannot do a git pull, unable to write to pack directory

I receive the following error when doing a simple git pull:

remote: Azure Repos
remote: Found 357 objects to send. (13 ms)
Receiving objects: 100% (357/357), 915.27 KiB | 614.00 KiB/s, done.
Resolving deltas: 100% (232/232), completed with 44 local objects.
error: unable to write file .git/objects/pack/pack-a1106a9b7ac7c2f544e979878a1468e633e5fb94.pack: Permission denied
fatal: cannot store pack file
fatal: index-pack failed

This appears to be a new problem but as far as I can figure out, nothing fundamental has changed on my machine since my previous successful pull.

I have tried to run the shell as admin but this too does not make a difference.

I am also able to create and delete files as per normal into this folder.

Upvotes: 3

Views: 18131

Answers (6)

user26965840
user26965840

Reputation: 1

for me running this command helped to identify broken refs:

git fsck --full

then manually remove broken refs:

Remove-Item .git\logs\refs\remotes\origin\user\branch, Remove-Item .git\refs\remotes\origin\user\branch

Upvotes: 0

Mike Walton
Mike Walton

Reputation: 4386

In my case, I had installed a new version of Git, which had prompted me to restart my machine. I ignored it and then promptly forgot about the pending restart. Once I did that, the error went away.

Upvotes: 0

Noureddine Ettalhi
Noureddine Ettalhi

Reputation: 61

I got following error when trying to add file to stage :

error: unable to write file .git/objects/7a/e1a47cd4025d6d746721503ea5496de30ba3d7: Invalid argument
error: gradle.properties: failed to insert into database
error: unable to index file 'gradle.properties'
fatal: updating files failed

I got around it by closing the file from notepad++ and modified it on Git Bash directly.

Upvotes: 0

LykS
LykS

Reputation: 31

As you can see in the output of git pull the line which shows the error is:

error: unable to write file .git/objects/pack/pack-a1106a9b7ac7c2f544e979878a1468e633e5fb94.pack: Permission denied

To fix it run git gc ("gc" stands for garbage collection).


In my case git gc outputs:

error: bad ref for .git/logs/refs/remotes/origin/HEAD  
error: bad ref for .git/logs/refs/remotes/origin/master
fatal: bad object refs/remotes/origin/master
fatal: failed to run repack

to solve it follow this answer

Upvotes: 3

Koenigsberg
Koenigsberg

Reputation: 1798

In the past I ran into similar problems as well. Several checks should be done before jumping to more advanced solutions. This is just a checklist taylored for your specific scenario.


  • Check if you have permissions, i.e. if you execute the git pull command via CLI, make sure the CLI instance has proper authorization level. In case of Windows this would be "Run as administrator"
  • Disk space. This was already mentioned in the comments by @sk_pleasant and is mentioned here: Git 'fatal: Unable to write new index file' - however you already did exclude that
  • If it's a file - does it already exist? Note: e.g. .git can be a file OR a folder! Either is allowed from the perspective of the Windows filesystem!
    • Does .git/objects/pack/pack-a1106a9b7ac7c2f544e979878a1468e633e5fb94.pack already exist?
    • If so, is it used by another process or is locked for some other reason?
    • Check by attempting to do the modifications which are attempted by git pull manually instead, i.e. attempt to create the file by hand
  • If you are using Git Bash, make sure to quit all instances. In the past I observed Git Bash being able to lock whole folders after having visited them (even if the active instance does no longer point into the folder)

For me personally I found the most common issue for being unable to change files was them being used by some other process. In my case most commonly such processes are compilers, active CLI instances, archive managers.

In case you still have the previous clone you might check and see if any of these apply to your case.

Upvotes: 6

Paul
Paul

Reputation: 982

So I hesitantly post this as an answer but, alas, it is one. I deleted my repo and re-cloned and now I can git pull again.

Upvotes: 3

Related Questions