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.
(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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With