Skip to content

Instantly share code, notes, and snippets.

@gobinathm
Created March 6, 2017 18:24
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save gobinathm/96e27a588bb447154604963e09c38ddc to your computer and use it in GitHub Desktop.
Save gobinathm/96e27a588bb447154604963e09c38ddc to your computer and use it in GitHub Desktop.
Fix for Remote rejected shallow update not allowed after changing Git remote URL

Some Time there is a shallow update not allowed issue in your cloned GIT repo.

This means that you have to unshallow your repository. To do so you will need to add your old remote again.

git remote add origin <path-to-old-remote> After that we use git fetch to fetch the remaining history from the old remote (as suggested in this answer).

git fetch --unshallow origin And now you should be able to push into your new remote repository.

@reinaldorauch
Copy link

Many thanks my friend, helped a lot o/

@seta-hungDang
Copy link

Wow I get the same issue today. Thank you so much!

@ArLabDev
Copy link

ArLabDev commented Jun 18, 2020

Hello, I'm trying to push my local repo to my newly created github repo and I get this error.
But the git fetch --unshallow origin command fails with
fatal: couldn't find remote ref refs/head/master

Am I missing something?

@jrasor
Copy link

jrasor commented Jul 9, 2020

Same problem as ArtLabDev.

@codetot
Copy link

codetot commented Sep 11, 2020

If you see fatal: couldn't find remote ref refs/head/master, you must run git push origin HEAD:master first.

@asanodaria
Copy link

Thanks Dear @gobinathm. git fetch --unshallow origin worked for me...

@NoSpamDan
Copy link

Worked here too, thanks!

@MashinaMashina
Copy link

If you have not access to old repository, you can use

  1. git rebase -i --root
  2. in first commit change pick to edit
  3. git commit --amend --no-edit
  4. git rebase --continue

After your git will think what is not shallow.

source. How to fix shallow update not allowed in git

@Juliet-Simpson
Copy link

A zillion thank yous. You just saved my course project, I think I would fail if I submitted a shallow repo.

@Sergioamjr
Copy link

This worked for me:

git fetch --unshallow https://github.com/this_is_the_source_url_from_where_you_did_clone_it.git
git remote remove origin
git init
git remote add origin https://github.com/your_new_repository_url_here.git
git push origin master

@pang-lan
Copy link

pang-lan commented Jun 2, 2022

thanks!

@yurenchen000
Copy link

git checkout --orphan maybe work ?

@dushenyan
Copy link

Thank you very much😏

@GeorgeKontsevik
Copy link

nothing worked for me from answers above(

@Barathpalanisamy
Copy link

This worked for me:

git fetch --unshallow https://github.com/this_is_the_source_url_from_where_you_did_clone_it.git
git remote remove origin
git init
git remote add origin https://github.com/your_new_repository_url_here.git
git push origin master

its worked

@beijishiqidu
Copy link

😏

@CamiloD16
Copy link

Another option:

1 - Delete the file .git
2 - Use git init in the terminal
3 - Add again your repository

@microhello
Copy link

git fetch --unshallow https://github.com/this_is_the_source_url_from_where_you_did_clone_it.git
git remote remove origin
git init
git remote add origin https://github.com/your_new_repository_url_here.git
git push origin master

It's worked for me, thank you !

@Shankarv19bcr
Copy link

This worked for me:

git fetch --unshallow https://github.com/this_is_the_source_url_from_where_you_did_clone_it.git
git remote remove origin
git init
git remote add origin https://github.com/your_new_repository_url_here.git
git push origin master

its worked

@Barathpalanisamy Yeah Its Worked

@mariohernandez
Copy link

The answer in this article worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment