I want to mirror clone a Bitbucket Repository to another Bitbucket Repository. I manage this with a shell script, which does the following:
git clone --mirror <sourceUrl>
git remote set-url --push origin <targetUrl>
git push --mirror
Now I'm getting the following error when pushing because Bitbucket does not allow to push pull requests (which are created on the Source Bitbucket):
remote: You are attempting to update refs that are reserved for Bitbucket's pull
remote: request functionality. Bitbucket manages these refs automatically, and they may
remote: not be updated by users.
remote:
remote: Rejected refs:
remote: refs/pull-requests/21/from
remote: refs/pull-requests/23/from
remote: refs/pull-requests/23/merge
remote: refs/pull-requests/24/from
remote: refs/pull-requests/24/merge
To ...
! [remote rejected] refs/pull-requests/21/from -> refs/pull-requests/21/from (pre-receive hook declined)
! [remote rejected] refs/pull-requests/23/from -> refs/pull-requests/23/from (pre-receive hook declined)
! [remote rejected] refs/pull-requests/23/merge -> refs/pull-requests/23/merge (pre-receive hook declined)
! [remote rejected] refs/pull-requests/24/from -> refs/pull-requests/24/from (pre-receive hook declined)
! [remote rejected] refs/pull-requests/24/merge -> refs/pull-requests/24/merge (pre-receive hook declined)
error: failed to push some refs to '...'
I solved the Problem with a Hint from http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html by adapting the fetch refs with the following workaround.
I created a new bare Repository and adapted the config the following way:
[core]
repositoryformatversion = 0
filemode = true
bare = true
[remote "origin"]
fetch = +refs/heads/*:refs/heads/*
fetch = +refs/tags/*:refs/tags/*
url = <sourceUrl>
mirror = true
pushurl = <targetUrl>
Then I perform a Git Pull and Git Push and everything is fine.
Nevertheless the Workaround is not a beautiful solution because creating an empty bare repository and then overwriting it is weird so I want an alternative.
Questions:
fetch = +refs/*:refs/*
Configuration also with the "git clone" Command? This would solve the problem, that the Pull Requests are pulled initiallyThanks to Ivan.
His command solved my Problem. I only had to add the "-r" parameter to xargs to react on empty greps:
git show-ref | cut -d' ' -f2 | grep 'pull-request' | xargs -r -L1 git update-ref -d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With