If you ever had to download or backup your Gitlab repositories, you would probably have to do that manually for every repository you own. As of this writing, I had 54 and that was not my idea of a lazy afternoon. So I used the Gitlab API and with the help of Gitlab ‘Private Token’ setup this Python script to do the job for me.

import requests
import json
import os

def get_repo(repo):
    os.system("git clone " + repo)

def get_repos(r):
    res = json.loads(r.text)
    #print(res)

    for cnt,elem in enumerate(res):
        #print(elem)
        print(cnt, " --- ",elem['id'], elem['name'], elem['ssh_url_to_repo'])
        get_repo(elem['ssh_url_to_repo'])
        

headers = {'PRIVATE-TOKEN': YOUR_GITLAB_TOKEN}
#r = requests.get("https://gitlab.com/api/v4/projects?visibility=private&order_by=name&per_page=100", headers=headers)
#get_repos(r)

r = requests.get("https://gitlab.com/api/v4/projects?membership=yes&order_by=name&per_page=100", headers=headers)
get_repos(r)