I ended up calling the projects directly and using their respective namespaces to create the pathToFolder. So rather than cd'ing in and out just create the absolute paths.

import os
import gitlab
from git import Repo

GITLAB_TOKEN = os.getenv('GITLAB_TOKEN')

gl = gitlab.Gitlab(url='https://gitlab.example.priv', private_token=GITLAB_TOKEN)

gitBasePathRelative = "repos/"
gitBasePathRelativeAbsolut = os.path.expanduser("~/" + gitBasePathRelative)
os.makedirs(gitBasePathRelativeAbsolut,exist_ok=True)

for p in gl.projects.list(all=True):
    print("Cloning project " + p.name)
    pathToFolder = p.namespace['name'] + "/" + p.name
    if not os.path.exists(pathToFolder):
        print("\tCreating directory for project " + pathToFolder)
        os.makedirs(pathToFolder)
        Repo.clone_from(p.ssh_url_to_repo, pathToFolder)
Answer from user3063045 on Stack Overflow
🌐
PyPI
pypi.org › project › gitlab-clone
gitlab-clone · PyPI
Report project as malware · Tool for easy cloning whole gitlab structure to your local machine. Free software: MIT license · Requests · Python >= 3.6 · You can install “gitlab-clone” via pip: $ pip install gitlab-clone ·
      » pip install gitlab-clone
    
Published   Jan 23, 2023
Version   1.2.0
🌐
GitHub
github.com › oschweitzer › gitlab-cloning
GitHub - oschweitzer/gitlab-cloning: Python script to clone all Gitlab projects from a group
This repository contains a script written in Python that allows to clone all the projects from a Gitlab group using SSH or HTTP.
Author   oschweitzer
🌐
JetBrains
jetbrains.com › help › pycharm › clone-gitlab-project.html
Manage projects hosted on GitLab | PyCharm Documentation
January 12, 2026 - Select a repository from the list of all GitLab projects associated with your account and the organization that your account belongs to. In the Directory field, enter the path to the folder where your local Git project will be created. If you want to perform shallow clone with a limited history, select the Shallow clone with a history truncated to checkbox and specify the number of commits that you want to clone.
🌐
Python GitLab
python-gitlab.readthedocs.io › en › stable › faq.html
FAQ - python-gitlab v8.1.0
issue = gl.issues.list(get_all=False)[0] project = gl.projects.get(issue.project_id, lazy=True) editable_issue = project.issues.get(issue.iid, lazy=True) # you can now edit the object · See the merge requests example and the issues examples. python-gitlab does not provide an API to clone a project.
🌐
Python GitLab
python-gitlab.readthedocs.io › en › v2.9.0 › faq.html
FAQ — python-gitlab 2.9.0 documentation
How can I clone the repository of a project? python-gitlab doesn’t provide an API to clone a project. You have to use a git library or call the git command. The git URI is exposed in the ssh_url_to_repo attribute of Project objects.
🌐
Stack Overflow
stackoverflow.com › questions › 36789513 › clone-from-a-gitlab-community-private-repo-using-a-private-token-in-python-scrip
Clone from a Gitlab community private repo using a private token in Python script - Stack Overflow
June 3, 2016 - from os.path import abspath from git import Repo to_path = abspath("C:\mypath\test") Repo.clone_from("http://gitlab-ci-token:my_CI_token@myurl/testgroup/test.git", to_path)
🌐
GitHub
github.com › allista › gitlab-clone-all
GitHub - allista/gitlab-clone-all: Python scripts that help working with multi-repo projects hosted on a GitLab server.
Python scripts that help working with multi-repo projects hosted on a GitLab server. - allista/gitlab-clone-all
Starred by 13 users
Forked by 13 users
Languages   Python 99.6% | Shell 0.4% | Python 99.6% | Shell 0.4%
Find elsewhere
🌐
GitLab
docs.gitlab.com › topics › git › clone
Clone a Git repository to your local computer | GitLab Docs
This action creates a copy of the repository and establishes a connection that synchronizes changes between your computer and the GitLab server. This connection requires you to add credentials. You can either clone with SSH or clone with HTTPS. SSH is the recommended authentication method. ... Downloads all project files, history, and metadata to your local machine.
🌐
GitHub
github.com › python-gitlab › python-gitlab › issues › 573
Any gl_object for SSH/ git clone project details? · Issue #573 · python-gitlab/python-gitlab
August 21, 2018 - python-gitlab/docs/gl_objects/projects.rst After the project creation using the gl_object, how to clone the created project to workspace?? Could you please let me know if there is any gl_object ava...
Top answer
1 of 16
199

Update Dec. 2022, use glab repo clone

glab repo clone -g <group> -a=false -p --paginate

With:

  • -p, --preserve-namespace: Clone the repo in a subdirectory based on namespace
  • --paginate: Make additional HTTP requests to fetch all pages of projects before cloning. Respects --per-page
  • -a, --archived: Limit by archived status. Use with -a=false to exclude archived repositories. Used with --group flag

That does support cloning more than 100 repositories (since MR 1030, and glab v1.24.0, Dec. 2022)

This is for gitlab.com or for a self-managed GitLab instance, provided you set the environment variable GITLAB_URI or GITLAB_HOST: it specifies the URL of the GitLab server if self-managed (eg: https://gitlab.example.com).


Original answer and updates (starting March 2015):

Not really, unless:

  • you have a 21st project which references the other 20 as submodules.
    (in which case a clone followed by a git submodule update --init would be enough to get all 20 projects cloned and checked out)

  • or you somehow list the projects you have access (GitLab API for projects), and loop on that result to clone each one (meaning that can be scripted, and then executed as "one" command)


Since 2015, Jay Gabez mentions in the comments (August 2019) the tool gabrie30/ghorg

ghorg allows you to quickly clone all of an org's or user's repos into a single directory.

Usage:

$ ghorg clone someorg
$ ghorg clone someuser --clone-type=user --protocol=ssh --branch=develop
$ ghorg clone gitlab-org --scm=gitlab --namespace=gitlab-org/security-products
$ ghorg clone --help

Also (2020): https://github.com/ezbz/gitlabber

usage: gitlabber [-h] [-t token] [-u url] [--debug] [-p]
                [--print-format {json,yaml,tree}] [-i csv] [-x csv]
                [--version]
                [dest]

Gitlabber - clones or pulls entire groups/projects tree from gitlab
2 of 16
150

One liner with curl, jq, tr:

Copyfor repo in $(curl -s --header "PRIVATE-TOKEN: your_private_token" https://<your-host>/api/v4/groups/<group_id> | jq -r ".projects[].ssh_url_to_repo"); do git clone $repo; done;

For Gitlab.com use https://gitlab.com/api/v4/groups/<group_id>

To include subgroups add include_subgroups=true query param like

https://<your-host>/api/v4/groups/<group_id>?include_subgroups=true

Note: To clone with http url use http_url_to_repo instead of ssh_url_to_repo in jq (Thanks @MattVon for the comment)

🌐
Snyk
snyk.io › advisor › python packages › gitlab-clone
gitlab-clone - Python Package Health Analysis | Snyk
December 23, 2022 - The python package gitlab-clone receives a total of 102 weekly downloads. As such, gitlab-clone popularity was classified as limited. Visit the popularity section on Snyk Advisor to see the full health analysis. We found indications that gitlab-clone is an Inactive project.
🌐
PyPI
pypi.org › project › gitlabber
gitlabber · PyPI
Gitlabber clones or pulls all projects under a subset of groups / subgroups by building a tree from the GitLab API and allowing you to specify which subset of the tree you want to clone using glob patterns and/or regex expressions.
      » pip install gitlabber
    
Published   Nov 19, 2025
Version   2.1.0
🌐
Medium
medium.com › @sdmj45 › cloning-all-projects-from-gitlab-a-comprehensive-guide-d848763b3195
Cloning All Projects from GitLab: A Comprehensive Guide | by sdmj45 | Medium
June 28, 2024 - The provided Python script automates the cloning process. It performs the following actions: Initializes a connection to GitLab using your private token. Fetches all projects under a specified group, including those within subgroups.
🌐
GitLab
docs.gitlab.com › cli › repo › clone
glab repo clone | GitLab Docs
# Clones repository into current directory glab repo clone gitlab-org/cli glab repo clone https://gitlab.com/gitlab-org/cli # Clones repository into 'mydirectory' glab repo clone gitlab-org/cli mydirectory # Clones repository 'glab' for current user glab repo clone glab # Finds the project by the ID provided and clones it glab repo clone 4356677 # Clones a specific branch glab repo clone gitlab-org/cli -- --branch development # Clones with a shallow clone (depth 1) glab repo clone gitlab-org/cli -- --depth 1 # Clones with multiple Git flags glab repo clone gitlab-org/cli -- --branch main --sin
🌐
Google Groups
groups.google.com › g › gitlabhq › c › Neb1SfIrRPA
is this possible to clone all projects once oin gitlab group?
August 14, 2018 - You don't have permission to access this content · For access, try logging in If you are subscribed to this group and have noticed abuse, report abusive group
Top answer
1 of 9
57

It looks like there's not a straightforward solution for HTTPS-based cloning regarding GitLab. Therefore if you want a SSH-based cloning, you should take account these three forthcoming steps:

  • Create properly an SSH key using your email used to sign up. I would use the default filename to key for Windows. Don't forget to introduce a password! (tip: you can skip this step if you already have one ssh key here)

     $ ssh-keygen -t rsa -C "[email protected]" -b 4096
    
     Generating public/private rsa key pair.
     Enter file in which to save the key ($PWD/.ssh/id_rsa): [\n]
     Enter passphrase (empty for no passphrase):[your password]
     Enter same passphrase again: [your password]
     Your identification has been saved in $PWD/.ssh/id_rsa.
     Your public key has been saved in $PWD/.ssh/id_rsa.pub.
    
  • Copy and paste all content from the recently id_rsa.pub generated into Setting>SSH keys>Key from your GitLab profile.

     # Copy to clipboard
     pbcopy < ~/.ssh/id_rsa.pub
    
  • Get locally connected:

     $ ssh -i $PWD/.ssh/id_rsa [email protected]
    
     Enter passphrase for key "$PWD/.ssh/id_rsa": [your password]
     PTY allocation request failed on channel 0
     Welcome to GitLab, you!
     Connection to gitlab.com closed.
    

Finally, clone any private or internal GitLab repository!

$ git clone https://git.metabarcoding.org/obitools/ROBIBarcodes.git

Cloning into 'ROBIBarcodes'...
remote: Counting objects: 69, done.
remote: Compressing objects: 100% (65/65), done.
remote: Total 69 (delta 14), reused 0 (delta 0)
Unpacking objects: 100% (69/69), done.
2 of 9
43

You have your ssh clone statement wrong: git clone username [email protected]:root/test.git

That statement would try to clone a repository named username into the location relative to your current path, [email protected]:root/test.git.

You want to leave out username:

git clone [email protected]:root/test.git