Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitbucket clone all team repositories

I'd like to clone all my bitbucket team repositories using a bash script and http. I have found a few examples that use the Bitbucket api however, they all seem to return no repositories. Any ideas? Using mac.

like image 568
Imran Avatar asked Nov 04 '16 18:11

Imran


People also ask

How do I copy all repository at once?

(1) Right click inside the folder you want all of the repos to clone to (2) select "Git Bash Here" - Bash window will open (3) Edit the script with your org name, then copy and paste it into the bash window (maybe make sure line endings are unix based, not sure, I did just to be safe). (4) it should start running.

How do I list all repositories in Bitbucket?

Instead, you should always use https://api.bitbucket.org. Show activity on this post. "Returns a paginated list of all repositories owned by the specified account or UUID." according to the doco.

How do I clone a workspace in Bitbucket?

These instructions show you how to clone your repository using Git from the terminal. In the repository, select the Clone button. Copy the clone command. From a terminal window, change into the local directory where you want to clone your repository.


1 Answers

Here is my simple solution. Make file downloader.sh

#!/bin/bash

USER=${1}
TEAM=${2}

rm -rf "$TEAM" && mkdir "$TEAM" && cd $TEAM

NEXT_URL="https://api.bitbucket.org/2.0/repositories/${TEAM}?pagelen=100"

while [ ! -z $NEXT_URL ] && [ $NEXT_URL != "null" ]
do
    curl -u $USER $NEXT_URL > repoinfo.json
    jq -r '.values[] | .links.clone[1].href' repoinfo.json > ../repos.txt
    NEXT_URL=`jq -r '.next' repoinfo.json`

    for repo in `cat ../repos.txt`
    do
        echo "Cloning" $repo
        if echo "$repo" | grep -q ".git"; then
            command="git"
        else
            command="hg"
        fi
        $command clone $repo
    done
done

cd ..

you can run it by:

sh downloader.sh username teamname # or username instead team name
like image 98
Nikolay Galkin Avatar answered Oct 04 '22 18:10

Nikolay Galkin