如何使用GIT将所有存储库从Bitbucket克隆到Team中

时间:2014-01-23 16:06:17

标签: git clone bitbucket repository

我想知道从git开始是否可以从bitbucket克隆团队中的所有存储库。

提前致谢。

4 个答案:

答案 0 :(得分:8)

我已经组成this tiny Ruby script。测试它并echo调用中移除system(),以便实际进行克隆

#!/usr/bin/env ruby

# USAGE: ./clone ORG_NAME
# ( ./clone instedd )
require 'open-uri'
require 'json'

team = ARGV[0] || raise("Must specify organization name")

puts "Fetching https://bitbucket.org/!api/1.0/users/#{team}..."

data = JSON.parse(open("https://bitbucket.org/!api/1.0/users/#{team}").read)

data["repositories"].each do | repo |
  # delete "echo" for _actually_ cloning them
  system("echo #{repo["scm"]} clone https://bitbucket.org/#{team}/#{repo["slug"]}")
end

答案 1 :(得分:2)

git_cloner是一个免费的开源工具,我开发用于克隆一堆BitBucket或GitHub存储库。

示例:

git_cloner --type bitbucket --login user --password password https://my_bitbucket

使用REST API:

  1. 获取所有项目的JSON: http://my_bitbucket/rest/api/1.0/projects

    或者: http://my_bitbucket/rest/api/1.0/<user>/projects

  2. 为每个项目获取带有存储库的JSON:

    http://my_bitbucket/rest/api/1.0/projects/<project_name>/repos?limit=10000
    
  3. 通过JSON中的['links']['clone']['href']参数克隆回购。

  4. 完整示例:https://github.com/artiomn/git_cloner/blob/master/src/git_cloner/bitbucket.py

答案 2 :(得分:0)

  1. 下载jq
  2. 获取https://bitbucket.org/!api/1.0/users/[teamslug] w / authed浏览器检查cookie,找到bb_session cookie
  3. 执行以下替换[teamslug]和[bb_cookie]
  4. A=[teamslug]; BBCOKIE=[bb_cookie]; for repo in $(curl -s -o 'https://bitbucket.org/!api/1.0/users/$A' | jq --raw-output '.repositories[].slug'); do echo git clone https://bitbucket.org/$A/$repo >> all_team_repos; done

    1. sh all_team_repos

答案 3 :(得分:0)

对于我使用跟随脚本的hg,您可以将其用于git

import getpass
import requests
import urllib.parse
import json
import os

username = input('Username: ')
password = getpass.getpass("Password: ")

params = {
    "pagelen": 100
}
url = "https://api.bitbucket.org/2.0/repositories/%s" % username
url = url + "?" + urllib.parse.urlencode(params)
repos_data = requests.get(url, auth=(username, password))

repos_data = json.loads(repos_data.content)


for repo in repos_data["values"]:
    os.system("hg clone %s" % repo["links"]["clone"][1]["href"])