How can I copy Bitbucket repo to CodeCommit, including all branches, but excluding all history on all branches?
Reason for wanting to do this: Our config server reads from CodeCommit, but the source of truth is in Bitbucket. (The reason we do that is a long story.) We have a script that currently (and successfully) "copies" the Bitbucket repo to CodeCommit. We are investigating if we can improve our config server's response times by syncing to CodeCommit without all the history, so when ConfigServer does a clone or fetch, it doesn't take as long (currently 15-25 seconds response times are common).
We hoped we could simply add --depth 1
to our git clone --mirror
command. However, when pushing the mirrored repo to CodeCommit, we get an error. To see if it was just a CodeCommit issue, I tried do something similar to read from bitbucket and push back to a new bitbucket repo. I got a different, but similar error.
Here are the core steps. This works just fine without the --depth 1
:
git clone --mirror --depth 1 ssh://<bitbucket> RepoFolder
cd RepoFolder
git remote add codecommit ssh://<codecommit>
git remote update origin
aws codecommit create-repository --repository-name pvvts_configs-RepoFolder --repository-description 'Synced'
git push --mirror codecommit
The error occurs on the last command (the git push
). The error looks like:
remote: Unknown commit 2280a0e659a1232a402041c27d94d81fd5142edberror: unpack failed: Unknown commit 2280a0e659a1232a402041c27d94d81fd5142edb
Followed by an error such as the following for each branch:
[remote rejected] dev -> dev (unpacker error)
If I try to do something similar except pushing back to bitbucket, I get the following error. (I skip the aws create-repository step, and instead manually create the new repo first in bitbucket.)
error: Could not read 6b0189279671f3a8c7b190dbc8d7ec91c0bb808a To ssh://git@bitbucket.pearson.com/pvvts_configs/vtscoreconfigurations_for_testing_only_marnee_1g_copy.git ! [remote rejected] dev -> dev (shallow update not allowed)
I had read that you could now push from a shallow sync with Git 1.9 or later. I have git version 2.7.4. (See this answer to a question here: https://stackoverflow.com/a/21217267/1599362.) However, perhaps the limitation on pushing from shallow sync was removed from a normal clone, but not from a mirror
.
Is there a way to do this shallow sync? Is there some other way to accomplish my purpose of reducing the size of the copied repo in CodeCommit? (Note that config server itself does have an option to tell it to do a shallow clone.)
(I realize even if I can successfully do this "shallow sync", that config server might not play nicely with it, and it might not give the performance improvement that we want. Testing that would be the next step.)