Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to download all repositories from a Bitbucket account
# Bitbucket Git Downloader
# Copyright (c) Davide Gironi, 2021
# Released under GPLv3
# Downloads all the repository from a Bitbucket account
#!/bin/bash
# Bitbucket Git Downloader
# Copyright (c) Davide Gironi, 2021
# Released under GPLv3
DATAFOLDER=gitdata
if [ -z "$GIT_USERNAME" ]; then
echo "No GIT_USERNAME supplied"
exit
fi
if [ -z "$GIT_PASSWORD" ]; then
echo "No GIT_PASSWORD supplied"
exit
fi
if [ ! -d "$DATAFOLDER" ]; then
echo "data folder does not exists"
exit
fi
cd $DATAFOLDER
user=$GIT_USERNAME:$GIT_PASSWORD
url='https://api.bitbucket.org/2.0/user/permissions/repositories'
while [ ! "$url" == "null" ]
do
curl -u $user $url > repositories.json
jq -r '.values[] | .repository.links.html.href' repositories.json > repositories.txt
for repo in `cat repositories.txt`
do
REPOSITORYNAME=`basename "$repo"`
echo "Cloning" $REPOSITORYNAME
if [ -d $REPOSITORYNAME ]
then
cd $REPOSITORYNAME
git pull
cd ..
else
git clone $repo
fi
done
url=`jq -r '.next' repositories.json`
done
rm repositories.json
rm repositories.txt
cd -
#!/bin/bash
# Bitbucket Git Downloader
# Copyright (c) Davide Gironi, 2021
# Released under GPLv3
#downloads all the repository from a Bitbucket account
#set you credential
#to store your password use git credential helper
# git config --global credential.helper store
export GIT_USERNAME=gitusername
export GIT_PASSWORD=gitpassword
./bitbucketgitdownloader.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment