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

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

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


当前回答

我发现这些方法似乎都不适合我。放心燃烧这个死亡,但由于某种原因不能让其他选项正常工作。

预期的结果是回购“克隆”到另一个远程(即从Github到另一个提供商):

所有分支都在新的远程上创建 所有分支历史记录都在新的远程上创建 (我尝试的每个解决方案都错过了这一点) 所有标记都在新的远程上创建 源移动(给定) 非破坏性(暂停——mirror选项)

我看到的主要问题是,所有远程分支都没有在新的远程中重新创建。如果一个命令有,新的远程没有分支历史记录(即做一个git签出分支;Git日志不会显示预期的分支提交)。

我注意到git checkout -b branchname与git checkout branchname不相同(后者是我需要的)。我注意到git checkout -track branchname似乎没有拉出分支历史。

我的解决方案(基于powershell):

Function Git-FetchRemoteBranches {
$originalbranch = (git symbolic-ref HEAD).split("/")[-1]

Foreach ($entry in (git branch -r)) {

If ($entry -like "*->*") {
  $branch = $entry.split("->")[2].split("/")[1]
}
  else {$branch = $entry.split("/")[1]}

Write-Host "--Trying git checkout " -NoNewline
Write-Host "$branch" -Foreground Yellow

git checkout $branch

Remove-Variable branch -Force

""}

#Switch back to original branch, if needed
If ( ((git symbolic-ref HEAD).split("/")[-1]) -ne $originalbranch) {
"Switching back to original branch"
git checkout $originalbranch
Remove-Variable originalbranch -Force
}
}

git clone http://remoterepo
cd remoterepo
Git-FetchRemoteBranches
git remote add newremote
git push newremote --all
git push newremote --tags #Not sure if neeeded, but added for good measure

其他回答

我发现这些方法似乎都不适合我。放心燃烧这个死亡,但由于某种原因不能让其他选项正常工作。

预期的结果是回购“克隆”到另一个远程(即从Github到另一个提供商):

所有分支都在新的远程上创建 所有分支历史记录都在新的远程上创建 (我尝试的每个解决方案都错过了这一点) 所有标记都在新的远程上创建 源移动(给定) 非破坏性(暂停——mirror选项)

我看到的主要问题是,所有远程分支都没有在新的远程中重新创建。如果一个命令有,新的远程没有分支历史记录(即做一个git签出分支;Git日志不会显示预期的分支提交)。

我注意到git checkout -b branchname与git checkout branchname不相同(后者是我需要的)。我注意到git checkout -track branchname似乎没有拉出分支历史。

我的解决方案(基于powershell):

Function Git-FetchRemoteBranches {
$originalbranch = (git symbolic-ref HEAD).split("/")[-1]

Foreach ($entry in (git branch -r)) {

If ($entry -like "*->*") {
  $branch = $entry.split("->")[2].split("/")[1]
}
  else {$branch = $entry.split("/")[1]}

Write-Host "--Trying git checkout " -NoNewline
Write-Host "$branch" -Foreground Yellow

git checkout $branch

Remove-Variable branch -Force

""}

#Switch back to original branch, if needed
If ( ((git symbolic-ref HEAD).split("/")[-1]) -ne $originalbranch) {
"Switching back to original branch"
git checkout $originalbranch
Remove-Variable originalbranch -Force
}
}

git clone http://remoterepo
cd remoterepo
Git-FetchRemoteBranches
git remote add newremote
git push newremote --all
git push newremote --tags #Not sure if neeeded, but added for good measure

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

# 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 repo中出现的分支,你可以通过git branch -a看到它们)

Git push origin '*:*'

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

镜像存储库

创建存储库的裸克隆。

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/

要推送所有分支,可以使用以下任意一种(将REMOTE替换为远程的名称,例如“origin”):

git push REMOTE '*:*'
git push REMOTE --all

推送所有标签:

git push REMOTE --tags

最后,我认为你可以在一个命令中完成这一切:

git push REMOTE --mirror

然而,除此之外——镜子,也会推动你的遥控器,所以这可能不是你想要的。