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
- Create a personal access token for GitLab that has the
API
permissions. In your terminal, store this key in an env variable. - For each group you want to check out:
- Create a new directory where you want all the checkouts to live.
- In GitLab, navigate to the Group's overview page so you can see the Group ID.
- 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.
- Run
gita add *
in the directory where the repos live on your machine. - Run
gita fetch
,gita pull