Resolving the "shallow update not allowed" Git error

NicolasBrondinBernard

Author
@NicolasBrondinBernard

You've changed the remote origin of your project's repository and can't push your code? Here are the solutions!

Article published on 25/01/2022, last updated on 07/08/2026

If while running a "git push", your Git terminal started protesting with the following error:

"Remote rejected (shallow update not allowed)"

Then I'll explain where the problem comes from, what a shallow clone is, and I'll give you the solutions in this article!

The error

First of all, you should know that a "shallow clone" is not an error, but indeed a Git feature!

When you clone a repository, for one reason or another (deployment, for example), you tend to use the simple command "git clone [url]" in order to fetch the project.

But some projects, especially older ones, sometimes have such a substantial history that fetching all of it, with every change recorded since the project's creation, can considerably slow down the process.

It is therefore possible to specify an additional "--depth " parameter to specify the depth of history you want to fetch along with the project clone.

Since the history is not complete, this is called a "shallow clone", and so if you get the idea to modify the code and push the changes to a different origin than the initial one, then you will get the error in question.

git clone [url] --depth 1
git remote set-url origin [new_url]
git push origin master
-> Remote rejected (shallow update not allowed)

If you're not sure whether you've fetched a shallow project, you just need to go look inside the .git folder, if that's the case you'll have a file named "shallow" in the folder!

Note that sometimes a project ends up in a "shallow clone" state for a completely different reason, but the solutions are the same.

The solutions

There are two solutions, one "regenerative", and the other "degenerative", so you'll need to choose the one that best fits your use case.

Fixing the history

If you're developing the current project further and want to keep the history for traceability of the code produced, but simply want to change the remote repository, then you can retrieve all the missing history with the following command:

git remote add old-origin [old_url]
git fetch --unshallow old-origin
...

Then you can continue your operations as if nothing happened.

Starting from scratch

If your starting project was just a sample project (a boilerplate), or if the previous solution didn't work because a change desynchronized your local version from the original version, you can simply reset the git project, like this:

rm -r .git
git init
git remote add origin [url]
...

Be careful, as you've probably understood, this method is destructive and you'll lose all the history as well as the git project's configuration, however your current copy of the code will remain intact!


Phil Shaw sur Unsplash

Finished reading this article?
Our complete courses
Take it to the next level with our courses!

Complete courses, exercises and certificates to really learn programming!

4.8 average rating

Comments (0)

to leave a comment

No comments yet