我们需要将 BitBucket 中的存储库中的任何更改复制到 GitHub 中的存储库。哪个是跟踪所有分支的最佳选择?
经过一番调查,最好的方法是使用 BitBucket-pipelines。
所以,步骤是:
Settings / SSH keys
下生成新的 SSH 密钥并复制公共部分。在同一页面的“已知主机”部分,添加“github.com”。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!