GitLab CI shallow clone errors: GIT_DEPTH, git describe and missing origin/main

By Melih Toksari, developer of MergeBell · Updated · 4 min read

Short answer

GitLab CI jobs get a shallow clone: in new projects, only the last 20 commits, and only the pipeline's own branch or tag, plus the tags on those commits. So origin/main and other branches aren't there, and git diff origin/main...HEAD fails with "unknown revision or path not in the working tree". Once the latest tag is older than 20 commits, git describe fails with "No names found, cannot describe anything". Commit counts come out wrong, and pushing to another repository fails with "shallow update not allowed". Set GIT_DEPTH: "0" on the jobs that need history, and they fetch every branch and tag in full, or change Git shallow clone under Settings › CI/CD › General pipelines for every job.

A Git command that works on your computer fails in a GitLab CI job:

fatal: No names found, cannot describe anything.
fatal: ambiguous argument 'origin/main...HEAD': unknown revision or path not in the working tree.

The job has a shallow clone. Near the top of its log:

Fetching changes with git depth set to 20...

Here’s what a job fetches in GitLab 19.5, what breaks, and how to give a job the history it needs.

What a job fetches

New projects have a depth of 20, so each job gets the last 20 commits. Which refs it gets depends on the pipeline:

Pipeline Refs fetched
Branch That branch
Tag That tag
Merge request None, only the commit it runs
Any, with GIT_DEPTH: "0" Every branch and tag, full history

Tags that point at the fetched commits come along. Older tags, and other branches such as origin/main, don’t.

What breaks

git describe: “No names found”

fatal: No names found, cannot describe anything.

git describe needs a tag in the fetched history. It works while your latest tag is within the last 20 commits, then fails in every job. Version scripts and changelog tools that read tags fail the same way.

Other branches: “unknown revision”

fatal: ambiguous argument 'origin/main...HEAD': unknown revision or path not in the working tree.

origin/main isn’t fetched in a branch or merge request pipeline, so git merge-base origin/main HEAD fails too, with fatal: Not a valid object name origin/main. Fetching main in the script isn’t enough once the branch has more than 20 commits since it split off: the fork point isn’t in the shallow history, and the diff says:

fatal: origin/main...HEAD: no merge base

A commit outside the fetched history gives fatal: bad object and its SHA, such as $CI_COMMIT_BEFORE_SHA after a push of more than 20 commits.

Counts, logs and blame

  • git rev-list --count HEAD returns 20 on a linear history, a few more with merge commits, never the real count, so build numbers made from it go wrong.
  • git log and changelog scripts see only the fetched history.
  • SonarQube warns that it detected a shallow clone and has no blame information for the files.

Pushing: “shallow update not allowed”

! [remote rejected] HEAD -> main (shallow update not allowed)

A shallow clone can’t be pushed to a repository that lacks the history it’s missing, such as a mirror on another host. Pushing back to the same GitLab project works, because it has that history.

Fix: GIT_DEPTH “0” on the jobs that need it

release:
  variables:
    GIT_DEPTH: "0"
  script:
    - git describe --tags
  • GitLab fetches every branch and tag, with full history, and the log says Fetching changes... with no depth.
  • Set it per job, so other jobs keep the faster shallow clone. Under the top-level variables, it applies to every job.
  • A larger number, such as GIT_DEPTH: "200", helps git describe and commit counts, but the job still fetches only its own branch or tag.

To list a merge request’s changed files, compare with its target branch:

lint-changed:
  variables:
    GIT_DEPTH: "0"
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  script:
    - git diff --name-only "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD"

The three dots compare with the point where the branches split, so the list holds only the merge request’s changes, in merged results pipelines too. rules: changes needs no history in the job: GitLab checks it when it creates the pipeline. More on these pipelines in GitLab merge request pipelines.

Or unshallow in the script

script:
  - git fetch --unshallow --tags origin

This fetches the full history, every branch and every tag, into the job’s shallow clone. On a full clone, it fails with fatal: --unshallow on a complete repository does not make sense, so use it only in jobs that keep the default depth.

Change the default for the project

With the Maintainer role, go to Settings › CI/CD, expand General pipelines, and under Git strategy, change Git shallow clone:

  • 0, or empty: every job gets a full clone, with every branch and tag. Large repositories take longer to fetch.
  • A number up to 1000: the depth for every job.

A GIT_DEPTH variable, in .gitlab-ci.yml or the project’s CI/CD variables, overrides the setting.

On your phone

MergeBell shows a job’s log live, including the Fetching changes with git depth set to 20... line near the top, and Retry reruns the job on the free tier. A retry uses the project’s current Git shallow clone setting, so after a Maintainer changes it in a browser, a retry fetches the new depth, unless a GIT_DEPTH variable is set; a change to .gitlab-ci.yml needs a new commit. More in how to retry a failed GitLab pipeline.

Frequently asked questions

Why does git describe fail in GitLab CI with "No names found, cannot describe anything"?

The job has a shallow clone: by default the last 20 commits, with only the tags that point at them. Once your latest tag is older than that, git describe finds none. Set GIT_DEPTH: "0" on the job to fetch the full history and every tag, or run git fetch --unshallow --tags origin at the start of its script.

Why is origin/main missing in my GitLab CI job?

With a shallow clone, a branch pipeline fetches only its own branch, and a merge request pipeline only the commit it runs, so origin/main isn't there and git diff origin/main...HEAD fails with "unknown revision or path not in the working tree". Set GIT_DEPTH: "0" on that job, and GitLab fetches every branch and tag with full history.

What is the default GIT_DEPTH in GitLab CI?

New projects fetch 20 commits. The default comes from Git shallow clone under Settings › CI/CD › General pipelines, which accepts up to 1000, or 0 or empty for full clones. A GIT_DEPTH CI/CD variable overrides it: in .gitlab-ci.yml for the pipeline or a single job, or in the project's CI/CD variables. The job log shows the depth used: "Fetching changes with git depth set to 20..."

How do I make a full clone in GitLab CI?

Set GIT_DEPTH: "0" in the job's variables. GitLab then fetches every branch and tag with full history, and turns a shallow clone left by an earlier job into a full one. For every job, set Git shallow clone under Settings › CI/CD › General pipelines to 0 or leave it empty; large repositories then take longer to fetch.

Why does git push from GitLab CI fail with "shallow update not allowed"?

The job pushes its shallow clone to a repository that doesn't have the missing history, such as a mirror on another host. Set GIT_DEPTH: "0" on that job, or run git fetch --unshallow before the push. Pushing back to the same GitLab project works, because it has the history.

Sources

Checked against these pages on 10 November 2026. GitLab changes quickly — if something here no longer matches, tell us and we will fix it.

Do this from your phone with MergeBell

Free for the whole review loop: the To-Do inbox, diffs and line comments, approve and merge, pipelines with retry, and push alerts for your To-Dos. Works with gitlab.com and self-managed GitLab 16.0+.

Get MergeBell for iPhoneGet MergeBell for Android

On the App Store for iOS 26 or later and on Google Play for Android 12 or later. An independent app, not affiliated with GitLab Inc.