I added to the app.ini file the recommended values:
[git.timeout]
GC = 7200
I ran outside of gitea (but on the server) the following code on each repository:
git gc --prune --aggressive
On the bigger repositories, I saw that it was running out of memory. I increased the swap (1024 instead of 100).
After this change, the gc command could be passed everywhere.
I restarted the gitea service and forced the garbage collector in gitea.
This time only the three largest repositories are in error.