如何将GIT代码从bitbucket复制到github

问题描述 投票:0回答:1

我们需要将 BitBucket 中的存储库中的任何更改复制到 GitHub 中的存储库。哪个是跟踪所有分支的最佳选择?

git github bitbucket bitbucket-pipelines
1个回答
0
投票

经过一番调查,最好的方法是使用 BitBucket-pipelines。

所以,步骤是:

  1. 在 github 上,创建新的存储库。
  2. 在 bitbucket 上,在存储库的
    Settings / SSH keys
    下生成新的 SSH 密钥并复制公共部分。在同一页面的“已知主机”部分,添加“github.com”。
  3. 在 github 存储库设置中,添加公共 ssh 密钥作为部署密钥,并具有写入权限。
  4. 现在在您的工作副本中,您需要使用以下内容创建文件
    bitbucket-pipelines.yml
    (请记住替换 git 存储库 url):
pipelines:
  default:
    - step:
        script:
          # bitbucket options will fetch just the current branch, so it is required to fetch all:
          - git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
          # fetch all branches:
          - git fetch --all
          # track all branches but HEAD and the current one, which is already being tracked:
          - for i in $(git branch -a | grep remotes | grep -v "HEAD" | grep -v "$(git rev-parse --abbrev-ref HEAD)"); do git branch --track ${i#remotes/origin/} $i; done
          # publish the current working copy to gtithub
          - git push --mirror <GIT REPOSITORY URL HERE>

现在,如果您想做相反的事情,从 GitHub 复制到 BitBucket,可能很容易创建一个执行完全相同步骤的 github-action!

© www.soinside.com 2019 - 2024. All rights reserved.