我有一个本地Git回购,我想把它推到一个新的远程回购(全新的回购设置在Beanstalk上,如果这很重要的话)。 我的本地回购有一些分支和标签,我想保留我的所有历史。

看起来我基本上只需要做一个git推送,但这只上传主分支。

我如何推动所有东西,以便在遥控器上获得本地回购的完整副本?


当前回答

下面的命令将推送所有的分支(包括那些你从未签出但在你的git repo中出现的分支,你可以通过git branch -a看到它们)

Git push origin '*:*'

注意:当您正在迁移版本控制时,此命令非常方便 (我的服务。e从Gitlab迁移到GitHub)

其他回答

运行以下命令将现有的存储库移动到带有所有分支和标签的新远程:

cd existing_repo
git remote rename origin old-origin
git remote add origin git@<repo-url.git>
for remote in `git branch -r `; do git checkout --track remotes/$remote ; done
git push -u origin --all
git push -u origin --tags

如果目的地是空的,这是我发现的最简洁的方法。切换到一个空文件夹,然后:

# Note the period for cwd >>>>>>>>>>>>>>>>>>>>>>>> v
git clone --bare https://your-source-repo/repo.git .
git push --mirror https://your-destination-repo/repo.git

用https://..。对于文件:///your/repo等。

git-push的手册值得一读。结合这个网站,我在我的。git/config中写了以下内容:

[remote "origin"]
    url = …
    fetch = …
    push = :
    push = refs/tags/*

push =:表示“推送任何‘匹配的’分支(即已经存在于远程存储库并且有本地对应的分支)”,而push = refs/tags/*表示“推送所有标签”。

所以现在我只需要运行git push来推送所有匹配的分支和所有标签。

是的,这不是OP想要的(所有要推送的分支必须在远程端已经存在),但是对于那些在谷歌搜索“如何同时推送分支和标签”时发现这个问题的人来说可能是有帮助的。

镜像存储库

创建存储库的裸克隆。

git clone --bare https://github.com/exampleuser/old-repository.git

镜像推送到新的存储库。

cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git

删除在步骤1中创建的临时本地存储库。

cd ..
rm -rf old-repository.git

镜像包含Git大文件存储对象的存储库

创建存储库的裸克隆。将示例用户名替换为拥有存储库的个人或组织的名称,并将示例存储库名称替换为希望复制的存储库的名称。

git clone --bare https://github.com/exampleuser/old-repository.git

导航到刚才克隆的存储库。

cd old-repository.git

导入存储库的Git大文件存储对象。

git lfs fetch --all

镜像推送到新的存储库。

git push --mirror https://github.com/exampleuser/new-repository.git

将存储库的Git大文件存储对象推到镜像。

git lfs push --all https://github.com/exampleuser/new-repository.git

删除在步骤1中创建的临时本地存储库。

cd ..
rm -rf old-repository.git

以上说明来自Github帮助:https://help.github.com/articles/duplicating-a-repository/

我最喜欢的(也是最简单的)方法

git clone --mirror  OLD_GIT_URL
cd  NEW_CREATED_FOLDER
git remote add NEW-REMOTE NEW_GIT_URL
git push  NEW-REMOTE --mirror