如何从 git 镜像克隆中排除拉取请求

How can I exclude pull requests from git mirror clone

我想将一个 Bitbucket 存储库镜像克隆到另一个 Bitbucket 存储库。 我使用 shell 脚本管理它,该脚本执行以下操作:

git clone --mirror <sourceUrl>
git remote set-url --push origin <targetUrl>
git push --mirror

现在我在推送时收到以下错误,因为 Bitbucket 不允许推送拉取请求(在 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 '...'

我通过以下变通方法调整获取引用,用 http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html 的提示解决了问题。

我创建了一个新的裸存储库并按以下方式调整了配置:

[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>

然后我执行 Git 拉和 Git 推,一切都很好。

尽管如此,解决方法并不是一个完美的解决方案,因为创建一个空的裸存储库然后覆盖它很奇怪,所以我想要一个替代方案。

问题:

感谢 Ivan。

他的命令解决了我的问题。我只需将“-r”参数添加到 xargs 即可对空 greps 做出反应:

git show-ref | cut -d' ' -f2 | grep 'pull-request' | xargs -r -L1 git update-ref -d