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.
fatal: protocol error: bad pack headerCommon 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.
# in the server account's ~/.bashrc, near the top:
case $- in *i*) ;; *) return;; esac # do nothing for non-interactive shellsIsolate where the noise comes from
- Run
ssh git@hostand confirm no banner/text prints before the prompt. - Check the remote PATH resolves a real
git-upload-pack(not a wrapper). - 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-shellfor Git-only accounts so no extra output is emitted. - Avoid HTTP proxies that modify response bodies for Git traffic.