When working with a distributed system made of many code repositories, it is tedious to clone each repository manually.
Below is how you could clone an entire GitLab group of repositories in one go.
-
Install GitLab CLI
glabfollowing installation steps in https://gitlab.com/gitlab-org/cli/#installation. -
Create a personal access token
-
If the GitLab instance has self-signed certificate, set to skip TLS or install the necessary certificates.
glab config set skip_tls_verify true --host gitlab.wltheng.com- Authenticate via
glabauth login. Below is a sample.
$ glab auth login
? What GitLab instance do you want to sign in to? GitLab Self-Managed or GitLab Dedicated instance
? GitLab hostname: gitlab.wltheng.com
? API hostname: gitlab.wltheng.com
- Signing into gitlab.wltheng.com
? How would you like to sign in? Token
Tip: generate a personal access token at https://gitlab.wltheng.com/-/user_settings/personal_access_tokens?scopes=api,write_repository.
The minimum required scopes are 'api' and 'write_repository'.
? Paste your authentication token: **************************
? Choose default Git protocol: SSH
? Choose host API protocol: HTTPS
- glab config set -h gitlab.wltheng.com git_protocol ssh
✓ Configured Git protocol.
- glab config set -h gitlab.wltheng.com api_protocol https
✓ Configured API protocol.
✓ Logged in as johndoe
✓ Configuration saved to /Users/johndoe/.config/glab-cli/config.yml- Use
glab repo clone -g <group> --paginateto clone a group.
# This clones all repositories under https://gitlab.wltheng.com/foo
GITLAB_HOST=gitlab.wltheng.com glab repo clone -g foo --paginate