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

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

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


当前回答

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

# 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等。

其他回答

实现目标的主要方法是使用——all和——tags标记。忽略其中任何一个都不能实现你想要的东西。不幸的是,它们不能一起使用(不知道为什么),所以它们必须一个接一个地运行。

git push --all
git push --tags

另一个相关的选项是——prune选项,它删除远程上本地不存在的任何分支/标签。

或者,考虑——mirror选项,因为它基本上等同于——all——tags——prune。

git push --mirror

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

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

推送所有标签:

git push REMOTE --tags

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

git push REMOTE --mirror

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

对我来说,有效的方法是。

git push origin --all

每次我谷歌如何做到这一点,我最终都会读到同样的帖子,但它并没有让我到达我需要的地方,所以希望这对我未来的自己和其他人也有帮助。

我开始了一个新的本地项目,我想把它推到我的回购(比特桶)。以下是我所做的:

导航到本地项目根目录 初始化:git init 使用:git Add添加所有文件。 git commit -m“初始提交” 去我的回购(BitBucket) 创建新的存储库:new_project 回到我的本地项目 add origin git@bitbucket.org:AndrewFox/new_project.git 使用:git Push origin master -f来提交

-f标志用于强制执行,否则它将识别出两个回购是不同的并失败。

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

预期的结果是回购“克隆”到另一个远程(即从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