Clone all Repos from a Bitbucket source

I have about 22 repositories on bitbucket and downloading them can be a pain. Here’s a short script to make life easier:

#!/bin/bash
#Script to get all repositories under a user from bitbucket
#Usage: getAllRepos.sh [username]

curl -u ${1}  https://api.bitbucket.org/1.0/users/${1} > repoinfo
for repo_name in `grep \"name\" repoinfo | cut -f4 -d\"`
do
	hg clone ssh://hg@bitbucket.org/${1}/$repo_name
done

UPDATE: Corrected a typo. Many thanks to fr3d3r1cbaz1n for pointing it out! Also, as fr3d3r1cbaz1n noted, this script only works for Mercurial but git users can easily change the hg command to git.

Advertisements

5 thoughts on “Clone all Repos from a Bitbucket source

  1. very helpful. Thank you !
    there is typo in filename. saving to repoinfo but reading from repoinfo.txt

    Also ,the script is not detecting repo type properly though. I was lazy to implement that part .
    As my repos are all git ,I just replace hg line with
    git clone git@bitbucket.org:${1}/$repo_name.git

  2. The line:
    for repo_name in `grep \”name\” repoinfo | cut -f4 -d\”`

    should actually be:
    for repo_name in `grep \”slug\” repoinfo | cut -f4 -d\”`

    The repo name on bitbucket can actually be a verbose name, while the slug is used in the URL for the repo.

  3. Would love to see an indempotent script that would git pull repo’s that already existed. Will post here if I get to it 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s