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?
CodePudding user response:
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.
CodePudding user response:
You don't. A shallow clone is made at git clone
time, by creating a .git/shallow
file with the right contents (commit hash IDs). The git push
command is unable to create or update this file; only git fetch
can update it, or remove it entirely, when changing the depth of, or "un-shallowing", a clone (with --depth
, --deepen
, or --unshallow
). The git init
command that creates a new, empty repository never creates this file; only git clone
(which runs git fetch
internally) and git fetch
can create or update it.
Your best bet is to find or create some full clone, and use that to push to the remote repository to which you have git push
access, then git push
your new commits from the existing shallow repository. If the full clone is very large (occupies too much space on your laptop for instance), you can remove it after copying it this way.
Side note: Git does not use the phrase shallow branch, only shallow clone or shallow repository. That's because the word branch, whatever you mean by it—different people mean different things at different times—doesn't really fit well here.