上下文
我正在编写一个脚本来镜像并定期从GitHub刷新一些存储库。 GitHub repos引用了外部没有任何意义的Pull请求分支,因此我按照Howto: Mirror a GitHub Repo Without Pull Refs中的建议过滤掉它们。到目前为止,步骤是
git clone --mirror SourceGitHubRepoUrl
git remote add --mirror=push alice MyMirrorUrl
git config --local --replace-all remote.origin.fetch "+refs/heads/*:refs/heads/*"
git config --local --add remote.origin.fetch "+refs/tags/*:refs/tags/*"
此时本地镜像具有正确的提取规则和
git remote update origin
效果很好,但是
git push --mirror alice
会出现! [remote rejected] refs/pull/22/head -> refs/pull/22/head
之类的错误,因为packed-refs
仍会列出refs/pull/*
分支。
问题
如何修复packed-refs
的内容?我可以简单地删除所有匹配“refs / pull”的行吗?
后者似乎有效,但人们永远不会确定没有潜伏的小鬼。
答案 0 :(得分:1)
在类似的情况下,我能够通过使用origin
和backup
的裸仓库将远程git-update-ref
逐步更新为镜像远程git-pack-refs
:
git fetch --all --prune
BRANCHES="$(git branch --remotes | grep origin/ )"
for BRANCH in $BRANCHES; do
echo "--> setting local branch ${BRANCH#origin/} to remote branch ${BRANCH}"
git update-ref "refs/heads/${BRANCH#origin/}" $(git rev-parse $BRANCH)
git pack-refs --all
done
echo "--> pushing to backup"
git push --mirror backup