This Python script mirrors all GitLab groups, subgroups, and projects you have access to into a local directory, preserving the exact GitLab hierarchy.
-
Fetches all top-level GitLab groups you have access to
-
Automatically includes all subgroups (recursive)
-
Clones every project into a local folder structure that matches GitLab:
group/ ├── project └── subgroup/ └── project -
If a repository already exists locally, it performs a
git pullinstead of re-cloning
Ideal for: - Creating local backups of GitLab repositories - Migrating or mirroring GitLab projects - Offline access to all group-based repositories - Keeping a local copy synchronized with GitLab
- Python 3.7+
gitinstalled and available in PATH- A GitLab Personal Access Token with repository access
Edit the following variables in the script:
ACCESS_TOKEN = "your_gitlab_access_token"
GITLAB_INSTANCE = "https://your.gitlab.instance"- Retrieves all root-level GitLab groups
- Requests all projects in each group (including subgroups)
- Builds folders based on
path_with_namespace - Clones or updates repositories accordingly
- Uses GitLab REST API v4
- Preserves GitLab folder structure exactly
- Works with self-hosted GitLab instances