Andreas Vöst
6 months
Andreas Vöst
8 months
Marc Dierig
11 months
Claus-Theodor Riegg
4 years
Andreas Vöst
4 years
Marius Schuller
5 years
Claus-Theodor Riegg
6 years
Claus-Theodor Riegg
7 years
Claus-Theodor Riegg
7 years
Claus-Theodor Riegg
7 years
Claus-Theodor Riegg
8 years

HowTo: Clone and refresh all repos in a GitLab Group

Updated . Posted . Visible to the public.

If the project you're working on has, say, 39 repositories and counting in GitLab and you need all the repos checked out for some reason, here's how to do it.

Checking out all repos

  1. Create a personal access token for GitLab that has the API permissions. In your terminal, store this key in an env variable.
  2. For each group you want to check out:
    1. Create a new directory where you want all the checkouts to live.
    2. In GitLab, navigate to the Group's overview page so you can see the Group ID.
    3. In the directory you created before, run the oneliner that checks out the code.

For example:

$ TOKEN=gl_blablabla
$ GITLAB_URL=https://gitlab.com
$ mkdir awesome_microservice_project && cd awesome_microservice_project
$ mkdir devops && pushd devops
$ GROUP_ID=313373
$ for repo in $(curl -s --header "PRIVATE-TOKEN: your_private_token" $GITLAB_URL/api/v4/groups/$GROUP_ID | jq -r ".projects[].ssh_url_to_repo"); do git clone $repo; done;
$ popd
$ mkdir terraform && pushd terraform
$ GROUP_ID=313374
$ for repo in $(curl -s --header "PRIVATE-TOKEN: your_private_token" $GITLAB_URL/api/v4/groups/$GROUP_ID | jq -r ".projects[].ssh_url_to_repo"); do git clone $repo; done;

etc.

Refreshing all the repos

If you then need to pull changes made by your colleagues, this one liner will check out all the files

$ for repo in $(find . -type d -name .git -exec dirname {} \;); do pushd $repo; git pull; popd; done

gita

You could use the tool gita from github/nosarthur Show archive.org snapshot . This is available in the ubuntu repo.

  1. Run gita add * in the directory where the repos live on your machine.
  2. Run gita fetch, gita pull
Emma Heinle
Last edit
Moritz Kraus
Tags
License
Source code in this card is licensed under the MIT License.