BlogGit

How to Troubleshoot a Slow Git Server: Four Outputs to Collect

Scott Sternloff

By Scott Sternloff, Senior Enterprise Architect

LinkedIn · Updated · 5 min read

How to Troubleshoot a Slow Git Server: Four Outputs to Collect
On this page

Short answer

A slow Git server is almost always one of four things: a client or server that is out of date, a repository with unmaintained packs, a server that is queueing requests, or one expensive Git command. Collect four outputs before you change anything: the Git version, git count-objects -vH, the platform's health output and a clone run with GIT_TRACE_PERFORMANCE. Together they tell you which of the four you have.

A slow Git server is almost always one of four things: a client or server that is out of date, a repository with unmaintained packs, a server that is queueing requests, or one expensive Git command. Collect four outputs before you change anything: the Git version, git count-objects -vH, the platform's health output and a clone run with GIT_TRACE_PERFORMANCE. Together they tell you which of the four you have.

This guide is for teams that run their own Git server or self-managed GitLab. If you would rather have an engineer on call for this, see our Git support page. Everything below is commands you can run yourself.

What four outputs should you collect first?

Collect them in this order, because each one rules something out before the next. Save them in a ticket or a text file, since the same four outputs are what any vendor, project or support engineer will ask for.

# Output Command What it rules in or out
1 Git version git version on the client and on the server Missing features, such as partial clone support
2 Repository shape git count-objects -vH in the server-side repository Loose objects, too many packs, garbage
3 Platform health gitlab-rake gitlab:env:info and gitlab-rake gitlab:check (GitLab) Misconfigured components, a stalled Gitaly check
4 Where the time goes GIT_TRACE_PERFORMANCE=1 git clone <url> Which Git command is slow: negotiation, packing or checkout

How do you read git count-objects?

Run git count-objects -vH inside the repository. The -v flag adds the detail and -H prints human-readable sizes. The Git documentation defines the fields you care about:

  • count: the number of loose objects, and size the disk they use.
  • in-pack and packs: how many objects sit in how many pack files.
  • size-pack: disk space used by the packs.
  • prune-packable: loose objects that are also in a pack, which git prune-packed can remove.
  • garbage and size-garbage: files in the object database that are neither valid loose objects nor valid packs.

A large count or a long tail of packs means the repository has not been repacked. A non-zero garbage value is worth following up, because those files are not valid objects or packs. A huge size-pack with healthy counts is a different problem: the repository is simply big, and the fix is on the client side (see below).

One rule before you act on any of this. If the repository belongs to GitLab, do not run git gc or git repack in it by hand. GitLab's housekeeping documentation says not to run housekeeping Git commands manually in repositories GitLab controls, because it risks corrupt repositories and data loss. Let Gitaly's housekeeping do it, and trigger it from GitLab if needed. On a plain Git server you control, garbage collection (git gc) or scheduled git maintenance is the usual fix for git performance problems caused by loose objects and many packs.

How do you find out which Git command is slow?

Set GIT_TRACE_PERFORMANCE for one run:

GIT_TRACE_PERFORMANCE=1 git clone https://git.example.com/group/repo.git

The Git documentation describes it as enabling performance-related trace messages, such as the total execution time of each Git command. If the time is spent before any data arrives, add GIT_TRACE_PACKET=1, which traces every packet in and out of a program and helps with object negotiation problems. Run the same clone from a machine on the server's own network. If it is fast there and slow from the office or the CI runner, the problem is the path or the client, not the repository.

How do you check the server side?

On a self-managed GitLab, run these on the node that runs GitLab Rails:

sudo gitlab-rake gitlab:env:info
sudo gitlab-rake gitlab:check

gitlab:env:info gathers configuration and system information that is useful when asking for help. gitlab:check runs several component checks, including gitlab:gitaly:check, and GitLab notes it must run from the application server, not from component servers such as Gitaly.

Then look at queueing. Gitaly can limit concurrent RPCs per repository with max_per_repo, max_queue_wait and max_queue_size. GitLab's documentation says that when these limits are reached, users are disconnected. If clones fail rather than crawl, check the Prometheus metrics Gitaly exposes for this, gitaly_concurrency_limiting_queued and gitaly_pack_objects_queued, before you raise any limit.

What do you change first?

Change settings before you touch history. In rough order of risk, lowest first:

  1. Shallow clone for CI. git clone --depth=1 truncates history to one commit, which also implies --single-branch. Add --no-tags if the job does not need tags.
  2. Partial clone. git clone --filter=blob:none asks the server to send everything except file contents until Git needs them. For large files, --filter=blob:limit=<size> leaves out only blobs of at least that size. The server must allow it: Git's uploadpack.allowFilter option enables partial clone and partial fetch filtering in upload-pack.
  3. Sparse checkout. git clone --sparse starts with only the top-level directory, and git sparse-checkout grows the working tree on demand.
  4. Scheduled maintenance on developer clones. git maintenance start registers the repository. Per Git's documentation the registered defaults are commit-graph and prefetch hourly, and loose-objects and incremental-repack daily, with gc disabled.

Our Jenkins, GitHub Actions and GitLab CI comparison covers where the CI runner choice changes these clone patterns.

When should you escalate?

Escalate when the four outputs point at the platform and not the repository: a Gitaly queue that stays full, gitlab:check failures you cannot explain, or a slow command that is slow on every repository. Send the four outputs with the exact versions, the time of the slow run and the clone command. A case with those four items attached starts a step ahead. If you want a 24/7 on-call route for this, response targets run from 15 minutes, by plan.

FAQ

Why is git clone slow on my own server but fast on GitHub?

Usually the repository, not the network. Run git count-objects -vH on the server copy: many loose objects or many packs mean it needs repacking, and a very large size-pack means clients should use --filter=blob:none or --depth. Then compare a clone from the server's own network.

Is it safe to run git gc on a GitLab repository?

Not by hand. GitLab's housekeeping documentation says not to run housekeeping Git commands manually in repositories that GitLab controls, because it can corrupt repositories. Use GitLab's own housekeeping, which Gitaly runs.

What does GIT_TRACE_PERFORMANCE show?

Performance-related trace messages, such as the total execution time of each Git command. Set it for a single clone, fetch or checkout to see which command takes the time, then add GIT_TRACE_PACKET=1 if negotiation looks slow.

Sources

Scott Sternloff

Author

Scott SternloffSenior Enterprise Architect

Senior Enterprise Architect at AceMQ. Writes the technical coverage here: RabbitMQ, Kafka and Redis architecture, clustering and migrations.

Talk to an engineer

Need a hand with Git?

Senior engineers who run it in production. Get a quote or a free consultation, no sales pitch.

Free Consultation

Get Expert Eyes on Your Git Environment

Whether you're troubleshooting a production incident, planning a migration, or want a second opinion on your architecture — our team is ready. No pitch, just answers.

Email Us