In my GitLab repository, I have a group with 20 projects. I want to clone all projects at once. Is that possible?
(1) Right click inside the folder you want all of the repos to clone to (2) select "Git Bash Here" - Bash window will open (3) Edit the script with your org name, then copy and paste it into the bash window (maybe make sure line endings are unix based, not sure, I did just to be safe). (4) it should start running.
The idea is to use the git-clone to clone the repository. This will automatically fetch all the branches and tags in the cloned repository. To check out the specific branch, you can use the git-checkout command to create a local tracking branch.
git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. The original repository can be located on the local filesystem or on remote machine accessible supported protocols. The git clone command copies an existing Git repository.
One liner with curl
, jq
, tr
:
for repo in $(curl -s --header "PRIVATE-TOKEN: your_private_token" https://<your-host>/api/v4/groups/<group_id> | jq ".projects[].ssh_url_to_repo" | tr -d '"'); 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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With