I am trying to sync my github repo with AWS codecommit. while trying to do git push sync --mirror
, I am not sure why it's trying to delete. Same code works fine for the master
branch, when I shift to preprod
branch it fails with the below error
remote: error: refusing to delete the current default branch 'refs/heads/master'.
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly
error: failed to push some refs to 'https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/test-repo'
Commands I am executing in my pipeline.
git config --global credential.'https://git-codecommit.*.amazonaws.com'.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
git remote add sync https://git-codecommit.eu-central-1.amazonaws.com/v1/repos/test-repo
git push sync --mirror
This is covered by the
git push
documentation, although you need to know what you're looking at:(emphasis mine)
Git, of course, has no idea what refs were "deleted": it just assumes that if you don't have some ref, such as
refs/heads/master
, in your repository, it should tell the other repository to delete its ref. So:This clearly means that your repository does not have a
refs/heads/master
, and yourgit push --mirror
is therefore asking them (whoever they are) to delete theirs too. But they're programmed to refuse to delete whatever branch name is set as the default branch.Remember that the default branch is the name they, whoever they are, will recommend that
git clone
check out at the end of the cloning process, should the person runninggit clone
fail to supply a-b
option. Most web hosting sites offer a way to set this name. Since you mention GitHub, consider usinggh
or their web API to set the default branch to something other thanmaster
to avoid the error. However...You mention in a comment that:
This strongly suggests that the repository from which you are running
git push
has only one branch name. As such, yourgit push --mirror
will delete all other branch names. If that's what you want, you're on the right track. If not, reconsider the use of--mirror
in the first place.