clone-all-gitlab.sh
A bash script that clones all accessible GitLab repositories from a GitLab instance, organizing them by their group/namespace structure.
export GITLAB_URL="https://your-gitlab-instance.com"
export GITLAB_TOKEN="your-personal-access-token"
curl https://albud.ca/clone-all-gitlab.sh | bash
What It Does
Main Features
- Clones all accessible repositories from a GitLab instance
- Preserves group/namespace directory structure (e.g.,
group/subgroup/project) - Updates existing repositories automatically if they have no uncommitted changes
- Skips repositories with uncommitted changes to prevent data loss
- Runs clone/update operations in parallel for faster execution
Configuration
Required Environment Variables
GITLAB_URL– The URL of your GitLab instanceGITLAB_TOKEN– Your GitLab Personal Access Token (PAT)
Optional Settings (edit script to customize)
CLONE_DIR– Directory where repos will be cloned (default: current directory)PAGE_SIZE– API pagination size (default: 100)CLONE_METHOD– Use “ssh_url_to_repo” or “http_url_to_repo” (default: ssh)MAX_PARALLEL_JOBS– Number of parallel clone operations (default: 10)
Requirements
curlfor API requestsjqfor JSON parsinggitfor cloning repositories- GitLab Personal Access Token with at least read_api and read_repository permissions