2014-10-20 66 views

回答

1

您可以原始回购的create a fork:这将创建一个新的回购直接在您的帐户在GitHub上。

POST /repos/:owner/:repo/forks 

假设您的帐户中尚未声明原始回购协议。

+0

这将工作,但我可能会想复制同一个存储库不止一次,似乎并不奏效。也许我做错了什么? – 2014-10-20 13:17:21

+0

@DekelAdler不,你没有做错任何事情:你可以创建每个回购只有一个分叉。 – VonC 2014-10-20 13:18:15

0

无论您是使用Github界面创建新的回购站还是使用Github RESTful API,都不允许在Github上重复复制。

一个存储库与一个唯一的名称是允许在用户帐户或组织之一。

1

使用Ruby和Octokit library你可以尝试服用点是这样的:

# Set Up 

class GithubCopy 

    def self.copy_repo(args) 
    from = args.fetch(:from) 
    to = args.fetch(:to) 

    client = Octokit::Client.new(:access_token => 'your access token') 

    base_items = client.contents from 
    self.copy_items(base_items, from, to, client) 
    end 

    private 

    def self.copy_items(base_items, from, to, client) 
    base_items.each do |item| 
     content = client.content from, :path => item.path 
     if content.is_a?(Array) 
     self.copy_items(content, from, to, client) 
     else 
     client.create_contents to, content.path, "Creating #{content.name}", Base64.decode64(content.content) 
     end 
    end 
    end 

end 

# Usage 
GithubCopy.copy_repo(from: 'repo1', to: 'repo2') 

这假定repo1repo2都存在,你的访问令牌有适当的权限都回购。如果你需要创建一个回购协议先使用此:

client = Octokit::Client.new(:access_token => settings.github_access_token) 
client.create_repository 'some-repo', {organization: 'some-org'} 

如果两个回购协议,你就会需要不同的名字在同一帐户下,作为@tmarwen说。一个缺点是这种方法可能需要一些时间,这取决于原始的回购规模。

相关问题