我正在尝试使用以下命令将一个存储库(repo1)的内容移动到另一个现有的存储库(repo2):
git clone repo1
git clone repo2
cd repo1
git remote rm origin
git remote add repo1
git push
但这并不奏效。我看过一篇类似的文章,但我只发现一个人移动了文件夹,而不是内容。
我正在尝试使用以下命令将一个存储库(repo1)的内容移动到另一个现有的存储库(repo2):
git clone repo1
git clone repo2
cd repo1
git remote rm origin
git remote add repo1
git push
但这并不奏效。我看过一篇类似的文章,但我只发现一个人移动了文件夹,而不是内容。
当前回答
对于那些使用GitHub的人,你可以通过web UI导入另一个存储库(包括历史):
https://github.com/new/import
其他回答
看起来你很接近了。假设不仅仅是提交一个错字,应该cd repo2代替repo1步骤3。第六步应该是拉而不是推。修改了列表:
Git克隆repo1 Git克隆repo2 cd repo2 Git远程rm来源 Git远程添加repo1 git拉 Git远程rm repo1 Git远程添加newremote
最简单的方法是,如果代码已经被Git跟踪,那么将新的存储库设置为要推送的“源”。
cd existing-project
git remote set-url origin https://clone-url.git
git push -u origin --all
git push origin --tags
我做了什么:
克隆存储库到一个文件夹 cd现有项目 这里打开一个git终端 git remote set-url origin <NEW_GIT_REPO> Git push -u origin——all Git push origin—tags
镜像存储库
根据@Dan-Cohn的回答,镜像推送是你的朋友。这是我的迁移回购:
1.打开Git Bash。
2.创建存储库的裸克隆。
$ git clone --bare https://github.com/exampleuser/old-repository.git
3.镜像推送到新的存储库。
$ cd old-repository.git
$ git push --mirror https://github.com/exampleuser/new-repository.git
4.删除在步骤1中创建的临时本地存储库。
$ cd ..
$ rm -rf old-repository.git
参考文献和出处:https://help.github.com/en/articles/duplicating-a-repository
完美描述在这里https://www.smashingmagazine.com/2014/05/moving-git-repository-new-server/
首先,我们必须从现有的存储库中获取所有的远程分支和标签到我们的本地索引:
git fetch origin
我们可以检查任何缺失的分支,我们需要创建一个本地副本:
git branch -a
让我们使用新存储库的ssh克隆URL在现有的本地存储库中创建一个新的远程存储:
git remote add new-origin git@github.com:manakor/manascope.git
现在我们准备将所有本地分支和标签推到名为new-origin的新远程:
git push --all new-origin
git push --tags new-origin
让我们把new-origin设为默认远程:
git remote rm origin
重命名new-origin为just origin,使其成为默认远程:
git remote rename new-origin origin