如何使用 repo 工具镜像由多个 git 个存储库组成的项目

Howto use repo tool to mirror a project composed of several git repositories

我想为一个由多个 .git 存储库组成的项目创建一个分支,将它们全部推送到不同的(本地)存储库,但为每个个体维护完全相同的一组分支和标签 git回购。

此项目最初是使用 "repo" 工具下载的。有一个 manifest.xml 文件描述每个 .git 存储库的位置,使用 repo init 下载,然后 repo sync 克隆所有 git 存储库。

我会在这个例子中使用bitbucket.com,但不要把注意力集中在bitbucket上,只是一个例子。

这是我现在正在执行的步骤:

  1. 在 bitbucket 中创建一个空的 manifest.git 存储库。那么:

    cd existing-manifest.git
    git remote set-url origin ssh://git@bitbucket.com/project/manifest.git
    git push -u origin --all
    git push origin --tags
    
  2. 在 bitbucket 中手动创建 git 回购集。那么:

    #! /bin/sh
    for LINE in $(repo forall -c 'echo ${REPO_PROJECT}":"${REPO_PATH}')
    do
        REPO_PROJECT=$(echo $LINE | cut -f 1 -d ":")
        REPO_PATH=$(echo $LINE | cut -f 2 -d ":")
        pushd $REPO_PATH
        git remote add origin ssh://git@bitbucket.com/project/${REPO_PROJECT}.git
        git push -u origin --all
        git push origin --tags
        popd
    done
    

之后,手动编辑 manifest.xml 以更改每个项目的默认远程并在我的自定义存储库中提交新的 manifest.xml。

这是一个非常手动的过程,不是很友好。所以我的问题是:

  1. 是否可以通过某种方式改进此过程?
  2. 仅使用 "repo" 工具是否可行?

第二步可以改进。 repo forall 就够了,不需要用 for.

包裹起来
repo forall -p -c 'git remote add origin ssh://git@bitbucket.com/project/${REPO_PROJECT}.git \
                   && git push -u origin --all --tags'

manifest.xml可以有这些标签和属性,

<remote fetch="ssh://git@bitbucket.com/project" name="origin" />
<default remote="origin" revision="foo" />
<project name=bar path=bar />

它定义了一个默认的远程 origin,这样您就不需要为每个项目指定远程,除非其中一个或多个项目托管在其他地方。对于项目 bar,其默认远程将是 origin ssh://git@bitbucket.com/project/bar,用于获取和推送。