This error occurs when using an outdated Git version (typically 1.8.x on CentOS 7) that doesn't properly support shallow clone operations. The fix is to upgrade Git to version 2.x or disable shallow cloning in your CI/CD configuration.
The "fatal: git fetch-pack: expected shallow list" error indicates that Git failed during a fetch operation because it expected to receive shallow clone information from the remote server, but the communication protocol didn't work as expected. This error is almost always caused by using an outdated version of Git. Specifically, Git versions prior to 2.0 (such as Git 1.8.3.1 that ships with CentOS 7) have incomplete support for the shallow clone protocol. When these older versions attempt to perform fetch operations on shallow repositories, they fail because they cannot properly handle the protocol negotiation. The error commonly appears in CI/CD environments (GitLab CI, Jenkins, Travis CI, OpenShift) that run on CentOS 7 or other systems with older Git versions, particularly when shallow cloning is enabled to speed up builds.
First, verify which version of Git you're using:
git --versionIf the output shows Git version 1.8.x or earlier, you need to upgrade. Git 2.0+ is required for proper shallow clone support.
On CentOS 7, the default Git is version 1.8.3.1. Upgrade using the IUS repository:
# Remove the old git package (note: this may also remove gitlab-runner)
sudo yum remove -y git
# Install the IUS repository
sudo yum install -y https://repo.ius.io/ius-release-el7.rpm
# Install Git 2.x (e.g., git236 for Git 2.36)
sudo yum install -y git236
# Verify the new version
git --versionIf you removed gitlab-runner, reinstall it:
sudo yum install -y gitlab-runner
sudo systemctl enable gitlab-runner
sudo systemctl start gitlab-runnerIf upgrading Git isn't immediately possible, disable shallow cloning in your GitLab project:
Option 1: Via GitLab UI
1. Go to your project's Settings > CI/CD
2. Expand "General pipelines"
3. Find "Git shallow clone" and clear/remove the value
4. Save changes
Option 2: Via .gitlab-ci.yml
variables:
GIT_DEPTH: 0 # Disables shallow cloningThis forces a full clone, which works with older Git versions but takes longer.
Configure your GitLab Runner to use clone instead of fetch, which can avoid some shallow-related issues:
Edit your runner's config.toml:
[[runners]]
environment = ["GIT_STRATEGY=clone"]Or add it to your .gitlab-ci.yml:
variables:
GIT_STRATEGY: cloneThis ensures a fresh clone for each job rather than trying to fetch into an existing checkout.
If the error occurs on a repository that previously worked, the .git/shallow file may be corrupted:
# Remove the shallow file and re-fetch
rm -f .git/shallow
git fetch --unshallowOr, if you want to keep it shallow, delete and re-clone:
cd ..
rm -rf your-repo
git clone --depth 1 <repository-url>If you're seeing this error in OpenShift builds, ensure your build configuration includes the ref (branch or tag):
source:
type: Git
git:
uri: "https://github.com/your/repo.git"
ref: "main" # or your branch/tag nameMissing the ref field can cause shallow fetch failures.
For other Linux distributions:
Ubuntu/Debian (using PPA):
sudo add-apt-repository ppa:git-core/ppa
sudo apt update
sudo apt install gitAmazon Linux 2:
sudo yum install -y git
# Or use amazon-linux-extras if available
sudo amazon-linux-extras install git2From source (any system):
# Install dependencies
sudo yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker
# Download and compile
wget https://github.com/git/git/archive/refs/tags/v2.43.0.tar.gz
tar -xzf v2.43.0.tar.gz
cd git-2.43.0
make prefix=/usr/local all
sudo make prefix=/usr/local install### Why CentOS 7 Has This Problem
CentOS 7 ships with Git 1.8.3.1 (released 2013) by default, and its repositories don't include newer versions. This is because CentOS maintains package stability over features. Git 1.8.x lacks full support for the shallow clone protocol enhancements introduced in Git 2.0.
### The Shallow Clone Protocol
Shallow clones work by having the client send a "deepen" request during fetch, telling the server how much history it wants. The server responds with a "shallow" list indicating which commits are the boundary of the shallow history. Git 1.8.x has incomplete implementation of this protocol, causing the "expected shallow list" error when the server doesn't respond as the old client expects.
### Go Module Fetching
This error commonly appears when running go get or go mod download on systems with old Git. Go uses Git internally to fetch module dependencies, and many modules are fetched as shallow clones for speed. The fix is the same: upgrade Git.
### Docker Containers
If you're running Git operations inside Docker containers:
# Use an image with recent Git
FROM alpine:latest
RUN apk add --no-cache git
# Or on CentOS-based images
FROM centos:7
RUN yum install -y https://repo.ius.io/ius-release-el7.rpm && \
yum install -y git236### CI/CD Best Practices
When possible, use the CI platform's native checkout actions rather than manual Git commands:
- GitHub Actions: actions/checkout@v4 handles Git properly
- GitLab CI: Uses modern Git in its runners
- CircleCI: Provides checkout step with proper Git support
These built-in steps often avoid shallow clone issues because they use appropriate Git versions and configurations.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git