如何复制git存储库?(没有分叉)

cow*_*bop 99 git github

我有两个存储库,我需要将整个存储库复制到另一个存储库中,它与第一个存储库具有不同的访问级别.副本和母库不应链接在一起.

我是git的新手,如果有人可以帮助我,这将是非常棒的.

Lar*_*y K 179

请参阅https://help.github.com/articles/duplicating-a-repository

精简版:

为了完全复制,您需要同时执行裸克隆和镜像推送:

mkdir foo; cd foo 
# move to a scratch dir

git clone --bare https://github.com/exampleuser/old-repository.git
# Make a bare clone of the repository

cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
# Mirror-push to the new repository

cd ..
rm -rf old-repository.git  
# Remove our temporary local repository
Run Code Online (Sandbox Code Playgroud)

注意:以上内容适用于任何远程git repo,指令不是特定于github

上面创建了一个新的repo远程副本.然后将其克隆到您的工作机器.

  • 对于使用GitHub的这个答案,必须首先在GitHub上创建新的存储库. (7认同)
  • 如果旧的和新的存储库具有相同的名称(不是相同的git URL)会发生什么.因为我只是将"Jeremy.git"克隆到另一个"Jeremy.git"中 (2认同)

Qua*_*ong 21

你也可以使用git-copy.

用Gem安装,

gem install git-copy
Run Code Online (Sandbox Code Playgroud)

然后

git copy https://github.com/exampleuser/old-repository.git \
    https://github.com/exampleuser/new-repository.git
Run Code Online (Sandbox Code Playgroud)

  • “首先如何安装 gem?” 使这不再是最轻松的解决方案。 (8认同)

Abi*_*hen 12

2021 年 11 月更新

现在您可以轻松地从 github 中的另一个 VC 复制文件和文件夹。

脚步:

  1. 创建一个新的存储库
  2. 点击底部的导入代码按钮

导入代码

  1. 粘贴存储库的克隆 URL,然后单击开始导入

开始导入

导入成功完成后,您将收到电子邮件通知。

  • 当今最好的方法。必须点赞! (4认同)
  • 对于私人存储库,出现提示时,请使用具有存储库只读访问权限的个人访问令牌,而不是密码。此处记录:https://docs.github.com/en/get-started/importing-your-projects-to-github/importing-source-code-to-github/importing-a-repository-with-github-importer (2认同)

Mat*_*dim 8

如果要复制到GitHub,则可以使用GitHub Importer来完成。原始存储库甚至可以来自其他版本控制系统。

  • 这样效果很好,甚至可以保留历史记录-应该更高的评价 (3认同)

tim*_*tim 6

如果您只想使用现有存储库中的全部或大部分文件(即作为一种模板)创建一个新存储库,我发现最简单的方法是使用所需名称等创建一个新存储库,将其克隆到您的桌面,然后只需在其中添加您想要的文件和文件夹。

你没有得到所有的历史等,但在这种情况下你可能不想要。

  • 我以前就是这么做的,但我想必须有更好的方法。没有。验证一下才放心。 (2认同)