Marc Tompkins
Marc Tompkins

Reputation: 71

git push --mirror failing

My team uses AWS CodeCommit and my company provides a GitHub service hosted internally.

We keep a 'mirror' of a repo in CodeCommit in GitHub. That is, the repo in GitHub is only updated via pushes from AWS. The repo in GitHub is intended to be a mirror of what's in CodeCommit. We have an AWS CodeBuild project that does a git push --mirror when commits to CodeCommit master happen. This worked for years without a problem, recently it stopped working and I'm stumped. It's an intermittent failure. I've seen it fail 3 times, succeed once, and go back to failing consistently. This is the error.

git push --mirror [email protected]:TeamOrg/project-x.git
To git.companyname.com:TeamOrg/project-x.git
   70614194..8d256e66  origin/master -> origin/master
 * [new branch]        origin/bug-fix -> origin/bug-fix
 ! [remote rejected]   master (refusing to delete the current branch: refs/heads/master)
error: failed to push some refs to '[email protected]:TeamOrg/project-x.git'

I've compared the commit history between the master repo in CodeCommit and GitHub. I expected to find a commit in GitHub that wasn't in CodeCommit; it would be solved by doing a git push --rebase, the histories are the same except CodeCommit has new commits that haven't been pushed to GitHub because our push is broken.

Any ideas on how to find the cause?

I've considered adding --force and/or --rebase options to the push, but I'd prefer to understand the problem before guessing at solutions; especially since the problem is intermittent.

Upvotes: -1

Views: 74

Answers (1)

LeGEC
LeGEC

Reputation: 51780

It looks like the source repo does not have a local master branch (it only mentions an origin/master branch).

Note in your output:

   70614194..8d256e66  origin/master -> origin/master
 # and:
 ! [remote rejected]   master (refusing to delete the current branch: refs/heads/master)

the error message basically states "refusing to delete the master branch".

If this is indeed the case, git push --mirror will try to delete the master branch on the github repo, and this action is probably rejected because of branch protection rules on the github repo.


Double check the end result you wish to have.

For example: it is a bit surprising that your AWS repository has remote branches (e.g: references stored under refs/remotes/origin/*) rather than local branches (at least local to the AWS repo, references stored under refs/heads/*).

This may be an effect of someone running git push --mirror from their local repository to the AWS remote.

You can run git ls-remote [aws_remote] to view what references are stored there.

Once you are ok with the references stored on that aws repo, adjust the settings on github -- e.g: delete the master branch if this is the desired outcome, if there are any errors when pushing to github debug the issue.

Upvotes: 1

Related Questions