我有两个存储库,一个在Bitbucket中,另一个在Github中。
我要做的是:将Bitbucket的存储库合并到Github存储库中,同时保留Bitbucket的存储库的提交历史记录。合并后,Github的仓库应该具有自己的提交历史以及Bitbucket的存储库提交历史。我想避免在Github中创建新的存储库。
如何使用git进行上述操作?
答案 0 :(得分:0)
您可以尝试
克隆GitHub存储库
git clone <github-repo-url>
将Bitbucket存储库添加为克隆存储库中的远程存储
git remote add <some-remote-name> <bitbucket-repo-url>
使用选项--allow-unrelated-histories
git fetch <some-remote-name>
git merge --allow-unrelated-histories <remote-name>/<branch-name>
使用--force
选项推送到GitHub远程
git push --force <github-remote-name>
请注意,合并操作可能会导致合并冲突。您可以查看此How do you merge two Git repositories?了解更多选项。
答案 1 :(得分:0)
您可以在https://help.github.com/en/github/creating-cloning-and-archiving-repositories/duplicating-a-repository#mirroring-a-repository-in-another-location上查看git mirror
当您推送到Bitbucket时,它将允许您自动将更改拉到github。