How to clone all projects of a group at once in GitLab?

后端 未结 15 1430
[愿得一人]
[愿得一人] 2020-12-23 02:02

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

相关标签:
15条回答
  • 2020-12-23 02:57

    One liner with curl, jq, tr

    for repo in $(curl -s --header "PRIVATE-TOKEN: your_private_token" https://<your-host>/api/v4/groups/<group_id> | jq ".projects[].ssh_url_to_repo" | tr -d '"'); do git clone $repo; done;
    

    For Gitlab.com use https://gitlab.com/api/v4/groups/<group_id>

    0 讨论(0)
  • 2020-12-23 03:00

    Another way to do it with Windows "Git Bash" that has limited packages installed :

    #!/bin/bash
    curl -o projects.json https://<GitLabUrl>/api/v4/projects?private_token=<YourToken>
    i=0
    while : ; do
        echo "/$i/namespace/full_path" > jsonpointer
        path=$(jsonpointer -f jsonpointer projects.json 2>/dev/null | tr -d '"')
        [ -z "$path" ] && break
        echo $path
        if [ "${path%%/*}" == "<YourProject>" ]; then
            [ ! -d "${path#*/}" ] && mkdir -p "${path#*/}"
            echo "/$i/ssh_url_to_repo" > jsonpointer
            url=$(jsonpointer -f jsonpointer projects.json 2>/dev/null | tr -d '"')
            ( cd "${path#*/}" ; git clone --mirror "$url" )
        fi
        let i+=1
    done 
    rm -f projects.json jsonpointer
    
    0 讨论(0)
  • 2020-12-23 03:03

    If you are okay with some shell sorecery this will clone all the repos grouped by their group-id (you need jq and parallel)

    seq 3                                                                           \
    | parallel curl -s "'https://[gitlabUrl]/api/v4/projects?page={}&per_page=100&private_token=[privateToken]'
                         | jq '.[] | .ssh_url_to_repo, .name, .namespace.path'" \
    | tr -d '"'                                                                 \
    | awk '{ printf "%s ", $0; if (NR % 3 == 0) print " " }'                    \
    | parallel --colsep ' ' 'mkdir -p {2} && git clone {1} {3}/{2}'
    
    0 讨论(0)
提交回复
热议问题