64

I'm new to git. I'm want to push a large commit to a remote server but the problem is when I use

git push origin master

it return the error

Counting objects: 5009, done.
Delta compression using up to 16 threads.
fatal: unable to create thread: Resource temporarily unavailable
error: pack-objects died with strange error

So is there anyway I can set the max thread use for Delta Compression.

Thanks for help,

Yuan Chen

Yuan Chen
  • 1,117
  • 1
  • 11
  • 18
  • 1
    commands you can run to limit the amount of memory that packing may take by logging into the remote system `git config --global pack.windowMemory "100m" ` `git config --global pack.packSizeLimit "100m" ` `git config --global pack.threads "1"` – Adnan Feb 09 '18 at 21:46

4 Answers4

194

The error: "fatal: unable to create thread: Resource temporarily unavailable" strongly suggests you've run out of memory on the server, which can happen if you have a repository with lots of large files, which can cause re-packing to take a lot of memory, or limited virtual memory - either in general, or just for that account due to the ulimit setting.

Anyways, here's the commands you can run to limit the amount of memory that packing may take by logging into the remote system (as the user that git runs as) and typing these commands:

git config --global pack.windowMemory "100m"
git config --global pack.packSizeLimit "100m"
git config --global pack.threads "1"

Hope this works.

Linulin
  • 4,050
  • 1
  • 19
  • 13
Waqar
  • 1,941
  • 1
  • 11
  • 3
  • 36
    Lots of shared hosting solutions limit threads specifically. Usually taking this down to <10 solely with the last command in this answer solves the problem. – Qix - MONICA WAS MISTREATED Mar 24 '14 at 18:49
  • 4
    I had this problem on my shared host trying to `git push` to remote. Setting `pack.threads "10"` fixed it for me. I had a similar problem when trying to run `git gc` when it got to the re-pack stage. Same fix. Cheers. – Fuzzy Logic Mar 11 '15 at 02:42
  • 2
    If your server uses the smart http protocol, you might not be able to set a global config for the process. Instead, `cd` into the directory of the git repository itself and run the same commands without `--global`. – yig Jul 08 '15 at 19:09
  • 3
    I can confirm that with Inmotion shared hosting, setting `git config --global pack.threads "5"` is sufficient to solve the problem. Thanks! – coccoinomane Apr 24 '17 at 19:03
  • 1
    It saved my time. This answer should be accepted. Thanks. – hobbydev Jan 17 '19 at 00:39
  • I was testing different server configs setup, checking composer install issues 'til I found this. Thank you. – MsC Nov 21 '19 at 08:15
  • Bigger thanks! many solutions does'n help me, works only this – Oleh Diachenko Sep 13 '21 at 10:46
  • Many thanks - coming to this 5 years later and it just dug me out of a hole! – Peter F Oct 23 '22 at 23:59
53

In shared hosting we have limited cpu resources mostly 1 cpu so multi-threading does not work very well there. This error is due to limited cpu resource actually.

Just this one git setting is enough to resolve this.

git config --global pack.threads "1"

This is limiting git to create only one thread.

Muzaffar Mahmood
  • 1,688
  • 2
  • 17
  • 20
7

I've also stumbled upon this error. To make it simpler, this error occurs because you want to copy a 100mb file into a hdd with free space of 50mb (or less). To fix this, SSH into the server and run the following commands:

git config --global pack.windowMemory "100m"
git config --global pack.packSizeLimit "100m"
Linulin
  • 4,050
  • 1
  • 19
  • 13
Nguyen Kien
  • 195
  • 4
  • trying these returned ```xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun ``` – HappyHands31 Jan 30 '19 at 18:50
  • ^ If you have this issue please see this article: https://stackoverflow.com/questions/52522565/git-is-not-working-after-macos-mojave-update-xcrun-error-invalid-active-devel - Issue resolved – HappyHands31 Jan 30 '19 at 18:59
3

"unable to create thread: Resource temporarily unavailable" means an issue with the remote server (like no more memory available).

Regarding delta, you have the following config to tweak:

pack.deltaCacheSize

The maximum memory in bytes used for caching deltas in git-pack-objects(1) before writing them out to a pack.
This cache is used to speed up the writing object phase by not having to recompute the final delta result once the best match for all objects is found.
Repacking large repositories on machines which are tight with memory might be badly impacted by this though, especially if this cache pushes the system into swapping.
A value of 0 means no limit.
The smallest size of 1 byte may be used to virtually disable this cache. Defaults to 256 MiB.

pack.deltaCacheLimit

The maximum size of a delta, that is cached in git-pack-objects(1).
This cache is used to speed up the writing object phase by not having to recompute the final delta result once the best match for all objects is found. Defaults to 1000.

The SO question "Git pull fails with bad pack header error" references other pack-related configs.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250