如何将所有分支推送到新创建的仓库

时间:2018-06-22 07:10:06

标签: git github gitlab push

我们正在将我们的仓库从gitlab转移到github。

一个小的CI脚本负责传输,但是由于某些原因,我们无法发送所有分支:

async function gitlabToGithub({
  name,
  organization,
  token,
  travisToken,
  branches, // eslint-disable-line no-unused-vars
  origin,
  path,
  remove,
  exclude,
  tags,
}, cb) {
  try {
    if (remove) {
      await execa.shell(`curl -X DELETE -H 'Authorization: token ${token}' https://api.github.com/repos/${organization}/${name}`);
    }
    console.log(`Creating repository ${organization ? `${organization}/${name}` : name}`);
    const {
      html_url: htmlUrl,
      clone_url: cloneUrl,
    } = await createGitHubRepoPromise({ name, organization, token });
    const repo = htmlUrl.replace('https://github.com/', '');
    const remote = cloneUrl.replace('github.com', `${token}@github.com`);
    console.log('Activating travis');
    await activateTravisLoop({ repo, token });
    await execa.shell('sleep 7s');
    await syncTravisLoop({ token: travisToken });
    try {
      await execa.shell(`git -C ${path} remote add ${origin} ${remote}`);
    } catch (e) {
      await execa.shell(`git -C ${path} remote set-url ${origin} ${remote}`);
    }
    console.log(`Remote ${origin} configured for GitHub.`);
    console.log(`git -C ${path} fetch --all`);
    const { stdout: un } = await execa.shell(`git -C ${path} fetch --all`);
    console.log(un);

    console.log(`git -C ${path} branch -l`);
    const { stdout: unBisZero } = await execa.shell(`git -C ${path} branch -l`);
    console.log(unBisZero);
    console.log(`git -C ${path} branch -r`);
    const { stdout: unBis } = await execa.shell(`git -C ${path} branch -r`);
    console.log(unBis);

    // console.log(`git -C ${path} push ${origin} ${branches.join(' ').trim()}`);
    // const { stdout: deux } = await execa.shell(`git -C ${path} push ${origin} ${branches.join(' ').trim()}`);
    // console.log(deux);

    console.log(`git -C ${path} push ${origin} '*:*'`);
    const { stdout: deux } = await execa.shell(`git -C ${path} push ${origin} '*:*'`);
    console.log(deux);


    if (tags) {
      console.log(`git -C ${path} push --tags`);
      const { stdout: trois } = await execa.shell(`git -C ${path} push --tags`);
      console.log(trois);
    }

    if (exclude.length) {
      Promise.all(exclude.split(',').map((branch) => execa.shell(`git -C ${path} push ${origin} --delete ${branch}`).then(execa.shell(`git -C ${path} branch -D ${branch}`)))).then(() => {
        console.log(`git -C ${path} remote rm ${origin}`);
        execa.shell(`git -C ${path} remote rm ${origin}`).then(() => {
          if (cb) {
            cb();
          }
        }).catch((e) => {
          console.log('[ERROR] ', e.message);
          throw e;
        });
      }).catch((e) => {
        console.log('[ERROR] ', e.message);
        throw e;
      });
    }
  } catch (e) {
    console.log('[ERROR] ', e.message);
    throw e;
  }
}

我们尝试过许多选择,git push ${remote} --allgit push ${remote} */*,之前都进行过git fetch --all。没有任何帮助。

Creating repository bootstrap-styled/navigation-bar
Activating travis
Travis activated
Travis synced
Remote github configured for GitHub.
git -C /mnt/mesos/sandbox/builds/bootstrap-styled/navigation-bar fetch --all
Fetching origin
Fetching github
git -C /mnt/mesos/sandbox/builds/bootstrap-styled/navigation-bar branch -l
* (detached from 26957f2)
  github-snapshot
  master
git -C /mnt/mesos/sandbox/builds/bootstrap-styled/navigation-bar branch -r
  github/github-snapshot
  origin/0.0.4
  origin/0.0.5
  origin/1.0.0
  origin/1.0.1
  origin/1.0.2
  origin/1.1.3
  origin/1.1.4
  origin/1.1.5
  origin/1.1.6
  origin/HEAD -> origin/master
  origin/agd-dev
  origin/ajt-dev
  origin/dev
  origin/github-snapshot
  origin/master
  origin/v0.0.1
  origin/v0.0.2
  origin/v0.0.3
git -C /mnt/mesos/sandbox/builds/bootstrap-styled/navigation-bar push github '*:*'

git -C /mnt/mesos/sandbox/builds/bootstrap-styled/navigation-bar push --tags

[Success] repository created and configured for travis
git -C /mnt/mesos/sandbox/builds/bootstrap-styled/navigation-bar remote rm github

有人知道我能成功获得100%的成功吗?

1 个答案:

答案 0 :(得分:1)

我认为您对此考虑过多。有--mirror个无法完成工作的原因吗?

git clone --mirror old-url
# cd into the newly-clined repo
git push --mirror new-url