Englund0110
Englund0110

Reputation: 555

git push --mirror gives "failed to push some refs"

I am trying to create a script that can mirror my git repository to another repository. Everything goes fine, but it it keeps saying

[remote rejected] refs/pull/xx/head -> refs/pull/xx/head (The current action can only be performed by the system.)

The repository is cloned to a folder on my computer, and then pushed to another git. All files and history is cloned and pushed as it should, but this "error" keeps coming up. What can i do?

enter image description here

This is my script

git clone --mirror https://path1.com/_git/fredagsproject1
cd fredagsproject1.git
git remote set-url --push origin https://path2.com/_git/fredagsproject2
git push --mirror

Upvotes: 11

Views: 13791

Answers (2)

mayurva
mayurva

Reputation: 185

This is a follow-up to the answer by @torek. To avoid the remote rejected errors, try the following commands instead of git push --mirror.

git push --all
git push --tags

The --all option pushes all the refs under /refs/heads/, and the --tags option pushes all the refs under /refs/tags.

Most remotes will happily accept those refs. While it is possible to to use --force option with above commands, it is a destructive operation. Be extremely careful while exercising this option.

Upvotes: 0

torek
torek

Reputation: 488233

When you run git push, you have your Git call up another Git over the Internet-phone. Your Git hands their Git some objects (commits and the like), and then sends their Git a pile of requests:

  • please set refs/heads/branch to point to commit 1234567...
  • please set refs/tags/v1.2 to point to annotated tag object fedcba9...

and the like.

Using git push --mirror tells your Git to ask their Git to set every name that you have, using exactly the same name in the request. As the image shows (and you've copied to a text line), many of these names have the form:

refs/pull/xx/head

for some two-digit xx sequence.

Their Git is simply saying No: I refuse to set that name.

You can try adding --force, which tells your Git to send a command—set these names!—instead of a polite request, please set these names, but take a look at the reason that their Git returned along with the refusal:

The current action can only be performed by the system.

That seems to say: Hands off this name! I reserve it for my use, how dare you ask me to change my refs/pull/73/head! In which case the command form (as opposed to the polite request form) is likely to be refused as well.

Note that ref-names of the form refs/pull/number/head and refs/pull/number/merge are used internally by, among others, GitHub for its management of pull requests. It's likely that you should not even attempt to set these names—so if your attempts are failing, that's probably a good thing.

Upvotes: 19

Related Questions