【问题标题】:How to push all branch to newly created repo如何将所有分支推送到新创建的仓库
【发布时间】:2018-06-22 07:10:06
【问题描述】:

我们正在将我们的 repo 从 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% 的成功率吗?

【问题讨论】:

标签: git github gitlab push


【解决方案1】:

我觉得你想多了。 --mirror 不做这项工作有什么原因吗?

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

【讨论】:

    猜你喜欢
    • 2018-11-29
    • 2018-01-27
    • 2016-02-01
    • 2017-07-19
    • 1970-01-01
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多