Christoph Forster Christoph Forster - 4 months ago 52
Git Question

How can I exclude pull requests from git mirror clone

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: 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 by adapting the fetch refs with the following workaround.

I created a new bare Repository and adapted the config the following way:

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.


  • I can add the needed fetch Configuration with "git clone --config" (before git clone performs it's initial fetch) but can I remove the original
    fetch = +refs/*:refs/*
    Configuration also with the "git clone" Command? This would solve the problem, that the Pull Requests are pulled initially

  • Is it possible to remove the pull requests from the bare repository after the pull?

  • Is it possible to exclude the pull requests from the push?


Thanks 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