Remote rejected (shallow update not allowed) after changing Git remote URL

前端 未结 6 1008
悲&欢浪女
悲&欢浪女 2020-11-28 02:16

I have a project under Git version control that I worked on both a server and my local computer. I originally had the remote origin set as my local computer but I would now

6条回答
  •  一个人的身影
    2020-11-28 02:52

    As it seems you have used git clone --depth to clone your local version. This results in a shallow clone. One limitation of such a clone is that you can't push from it into a new repository.

    You now have two options:

    1. if you don't care about you're current or missing history, take a look at this question
    2. if you want to keep your full history, then continue reading:

    So, you want to keep your history, eh? This means that you have to unshallow your repository. To do so you will need to add your old remote again.

    git remote add old 
    

    After that we use git fetch to fetch the remaining history from the old remote (as suggested in this answer).

    git fetch --unshallow old
    

    And now you should be able to push into your new remote repository.


    Note: After unshallowing your clone you can obviously remove the old remote again.

提交回复
热议问题