我正在尝试使用以下命令将一个存储库(repo1)的内容移动到另一个现有的存储库(repo2):

git clone repo1
git clone repo2
cd repo1
git remote rm origin
git remote add repo1
git push

但这并不奏效。我看过一篇类似的文章,但我只发现一个人移动了文件夹,而不是内容。


当前回答

这工作移动我的本地回购(包括历史)到我的远程github.com回购。在GitHub.com上创建新的空回购后,我使用下面第三步中的URL,它工作得很好。

git clone --mirror <url_of_old_repo>
cd <name_of_old_repo>
git remote add new-origin <url_of_new_repo>
git push new-origin --mirror

我在https://gist.github.com/niksumeiko/8972566上找到了这个

其他回答

看起来你很接近了。假设不仅仅是提交一个错字,应该cd repo2代替repo1步骤3。第六步应该是拉而不是推。修改了列表:

Git克隆repo1 Git克隆repo2 cd repo2 Git远程rm来源 Git远程添加repo1 git拉 Git远程rm repo1 Git远程添加newremote

我使用下面的方法通过维护所有分支和提交历史来将我的GIT Stash迁移到GitLab。

将旧的存储库克隆到本地。

git clone --bare <STASH-URL>

在GitLab中创建一个空存储库。

git push --mirror <GitLab-URL>

最简单的方法是,如果代码已经被Git跟踪,那么将新的存储库设置为要推送的“源”。

cd existing-project
git remote set-url origin https://clone-url.git
git push -u origin --all
git push origin --tags

完美描述在这里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

这工作移动我的本地回购(包括历史)到我的远程github.com回购。在GitHub.com上创建新的空回购后,我使用下面第三步中的URL,它工作得很好。

git clone --mirror <url_of_old_repo>
cd <name_of_old_repo>
git remote add new-origin <url_of_new_repo>
git push new-origin --mirror

我在https://gist.github.com/niksumeiko/8972566上找到了这个