How to clone all projects of a group at once in Gi

2020-05-11 21:16发布

In my GitLab repository, I have a group with 20 projects. I want to clone all projects at once. Is that possible?

标签: git gitlab
14条回答
SAY GOODBYE
2楼-- · 2020-05-11 22:04

Yep it's possible, here is the code.

prerequisites:

pip install python-gitlab

#!/usr/bin/python3
import os
import sys
import gitlab
import subprocess

glab = gitlab.Gitlab(f'https://{sys.argv[1]}', f'{sys.argv[3]}')
groups = glab.groups.list()
groupname = sys.argv[2]
for group in groups:
    if group.name == groupname:
        projects = group.projects.list(all=True)

for repo in projects:
    command = f'git clone {repo.ssh_url_to_repo}'
    process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
    output, _ = process.communicate()
    process.wait()

Example:

  • create .py file (ex. gitlab-downloader.py)
  • copy-paste code from above
  • on Linux OS (or OSX) do chmod +x on the script file (ex. chmod +x gitlab-downloader.py)
  • run it with 3 params: Gitlab hostname, groupname, your Personal Access Token(see https://gitlab.exmaple.com/profile/personal_access_tokens)
查看更多
beautiful°
3楼-- · 2020-05-11 22:06

I have written the script to pull the complete code base from gitlab for particular group.

for pag in {1..3} // number of pages projects has span {per page 20 projects so if you have 50 projects loop should be 1..3}
do
curl -s http://gitlink/api/v4/groups/{groupName}/projects?page=$pag > url.txt
grep -o '"ssh_url_to_repo": *"[^"]*"' url.txt | grep -o '"[^"]*"$' | while read -r line ; do
l1=${line%?}
l2=${l1:1}
echo "$l2"
git clone $l2
done
done
查看更多
登录 后发表回答