Pushing to a remote git repository from a Bitbucket Pipeline build fails with error "shallow update not allowed"

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

When using Bitbucket Pipelines to push your code to another git provider, or to a hosting provider that accepts deployment using git push, the push operation might fail with the error shallow update not allowed

Environment

Bitbucket Cloud - Pipelines

If you're using Bitbucket Server or Datacenter, please refer to Unable to push new commit from shallow clone.

Diagnosis

From your pipeline build, pushing to another git remote repository or to a hosting provider that accepts deployment through git push fails with an error message similar to the below :

1 2 3 4 $git push <remote git address> To <remote git address>/<repository>.git ! [remote rejected] <reference> -> <reference> (shallow update not allowed) error: failed to push some refs to '<remote git address>/<repository>.git'

Or

1 2 3 To <remote git address> ! [remote rejected] stage -> stage (unpacker error) error: failed to push some refs to '<remote git address>/<repository>'

Cause

In order to improve the performance of builds, Bitbucket Pipelines by default performs a shallow clone of your repository with a depth of 50, meaning that only the last 50 commits will be cloned. This assists with the "Build Setup" phase, where the repository is cloned into the build container.

However, some external git providers do not accept pushes from a shallow clone, which causes them to reject the push and throw the error message.

Solution

Update the bitbucket-pipelines.yml configuration to execute a full clone of the repository, instead of a shallow clone :

1 2 3 4 5 6 7 8 9 clone: depth: full # do a full clone of the repository pipelines: default: - step: name: Cloning script: - echo "Clone all the things!"

If the above instructions do not assist in resolving the issue, please raise a support ticket or raise a community support ticket for further assistance with this.

Updated on February 27, 2025

Still need help?

The Atlassian Community is here for you.