Search code examples
gitshallow-clone

How to add a shallow branch to a repo without SSH access


I have a shallow clone that I need to push to a remote repository (the remote repository does not contain any of the history from that branch). When I try to push it, it gives me an error about "Shallow update not allowed".

I tried to do it on a "local" remote repository I just created and I (of course) get the same error. I did find OTOH that I can eliminate the error if I first copy the .git/shallow to the destination repository. But my "real" remote repository is one to which I do not have shell access, so I cannot just scp the file to it. How can I convince the remote Git to create this .git/shallow file for me?


Solution

  • It depends on the remote server, but you also have, on that remote server, the option to set in the target bare repository the receive.shallowUpdate option:

    git config --local --add receive.shallowUpdate true
    

    And locally, you can try first a git fetch --update-shallow to accept refs that require updating .git/shallow.

    If you cannot do those two option (one remote, one local), then you need to git fetch --unshallow and work from there.