}

Clone all repositories of a git server (works for gitolite, bitbucket, gitlab)

Created:

Gitolite

Gitolite provides an info command that will list all repositories.

ssh [email protected] info

To clone all repos of gitolite execute:

ssh [email protected] info | cut -f 2 | tail -n +3 | xargs -I {} -n 1 git clone ssh://[email protected]/{}

With this command we use the info command output and process it with cut,tail and execute git clone using xargs.

Butbucket

For bitbucket we are going to use theirs api to donwload repository information. Remeber to change BBA enviroment variable value to your username.

 BBA=BuckbucketUsername; curl --user ${BBA} https://api.bitbucket.org/2.0/repositories/${BBA} | grep -o '"ssh:[^ ,]\+' | xargs -L1 git clone

Gitlab

To clone all repositories for gitlab we are going to use gitlab api. You will need to generate the api token. The method is very similar to bitbucket, we process the ouput and then send it xargs to clone the repos.

TOKEN="PASTE_YOUR_PRIVATE_TOKEN_HERE"; PREFIX="ssh_url_to_repo"; curl --header "PRIVATE-TOKEN: $TOKEN" http://gitlab.com/api/v3/projects?per_page=100 | grep -o "\"$PREFIX\":[^ ,]\+" | awk -F ':' '{printf "ssh://"; for (i=2; i<NF; i++) printf $i "/"; print $NF}' | xargs -L1 git clone

Note that gitlab has pagination, we set the page size to 100. If you have more you will need to follow the link header information.