Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clone all git bitbucket repositories with a single script

How can I checkout all the git bitbucket repositories for a team using a bash script?

There are other questions for this topic however the bitbucket api mentioned in those answers does not exist anymore.

like image 965
ddcc3432 Avatar asked Sep 16 '25 19:09

ddcc3432


2 Answers

The following script will clone all repositories of a project:

for r in $(curl -s --user USER:PASS --request GET https://BITBUCKET-SERVER/rest/api/1.0/projects/PROJECT/repos | jq --raw-output '.values[].links.clone[].href')
do
    git clone $r
done
like image 105
Marcelo Ávila de Oliveira Avatar answered Sep 18 '25 10:09

Marcelo Ávila de Oliveira


The following script is working well to download all repositories from Bitbucket.

  1. UserName not email

  2. Create App-password from Bitbucket

  3. Run the script by sh script.sh

     #!/bin/bash
    
     user=username:password
    
     curl -u $user 'https://api.bitbucket.org/2.0/user/permissions/teams?pagelen=100' > teams.json
    
     jq -r '.values[] | .team.username' teams.json > teams.txt
    
     for team in `cat teams.txt`
     do
       echo $team
    
       rm -rf "${team}"
    
       mkdir "${team}"
    
       cd "${team}"
    
       url="https://api.bitbucket.org/2.0/repositories/${team}?pagelen=100"
    
       echo $url
    
       curl -u $user $url > repoinfo.json
    
       jq -r '.values[] | .links.clone[0].href' repoinfo.json > repos.txt
    
       for repo in `cat repos.txt`
       do
         echo "Cloning" $repo
         git clone $repo
       done
    
       cd ..
    
     done        
    
like image 42
Mudassir Ali Avatar answered Sep 18 '25 08:09

Mudassir Ali