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

I tried to merge some changes to master and got the following error:
“! [remote rejected] HEAD -> master (shallow update not allowed)”

I have a very simple CI pipeline setup (just pushes the code to production) and it’s been working fine for months up to this error.

I did some searching and some of the errors reference branching using “depth” - to my knowledge we haven’t branched that way.

Here are the docs I found:
https://gist.github.com/gobinathm/96e27a588bb447154604963e09c38ddc#:~:text=Some%20Time%20there%20is%20a,add%20your%20old%20remote%20again.&text=git%20fetch%20--unshallow%20origin,into%20your%20new%20remote%20repository.

And this:
https://stackoverflow.com/questions/28983842/remote-rejected-shallow-update-not-allowed-after-changing-git-remote-url

I tried creating a separate branch, pushed, and merged that and got the same error as well.

Please let me know if you might have some advice before I dig myself into a deeper hole.

The default strategy for clones done inside the CI Jobs is a shallow clone, for performance reasons.

If you are looking to commit and push from within a CI Job, you can change the strategy. An edited excerpt from the documentation is quoted below:

To reach the pipelines settings navigate to your project’s Settings > CI/CD.

General pipelines > Git shallow clone (default: 50)

To disable shallow clone and make GitLab CI/CD fetch all branches and tags each time, keep the value empty or set to 0.

1 Like

Thank you for your suggestion.

I haven’t tried this yet, but do you have any ideas why suddenly this would be an issue? This has been in place for months and was working fine until now.

Thank you again!

Can’t be sure without more information, but the change was introduced in 12.0, and only appears to impact newly created projects by default (existing projects would require opting in).

I made the change in the setting as suggested and this time the job succeeded!

I wish I knew more about that setting in particular and why it failed on this project this time, but that’s just my curiosity.

Thanks for your help!