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:

#Script to get all repositories under a user from bitbucket
#Usage: [username]

curl -u ${1}${1} > repoinfo
for repo_name in `grep \"name\" repoinfo | cut -f4 -d\"`
	hg clone ssh://${1}/$repo_name

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.

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${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