Skip to content
Latchkey

Git "fatal: protocol error: bad pack header" in CI

Git expected a pack stream but the first bytes were not a valid pack header. Almost always something injected extra text into the connection - a shell profile printing a banner, a wrong git binary on the server, or a proxy rewriting the body.

What this error means

A fetch or clone fails immediately with fatal: protocol error: bad pack header, typically over SSH to a self-hosted host or through a proxy. It is deterministic for that host/path.

git clone output
fatal: protocol error: bad pack header

Common causes

A login shell printing to stdout on the server

Over SSH, a remote .bashrc/.profile that echoes a banner or MOTD injects bytes into the Git stream, so the pack header is no longer the first thing Git reads.

Wrong git-upload-pack or a proxy rewriting the body

A misconfigured git-shell, a non-Git binary on the remote PATH, or an HTTP proxy that alters the response corrupts the protocol framing.

How to fix it

Stop the server shell from writing to stdout

Guard banner/echo output behind an interactive-shell check so non-interactive Git sessions stay silent.

server ~/.bashrc
# in the server account's ~/.bashrc, near the top:
case $- in *i*) ;; *) return;; esac   # do nothing for non-interactive shells

Isolate where the noise comes from

  1. Run ssh git@host and confirm no banner/text prints before the prompt.
  2. Check the remote PATH resolves a real git-upload-pack (not a wrapper).
  3. If a proxy sits in front, bypass it or confirm it does not rewrite the response body.

How to prevent it

  • Keep server shell init files silent for non-interactive sessions.
  • Use git-shell for Git-only accounts so no extra output is emitted.
  • Avoid HTTP proxies that modify response bodies for Git traffic.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →