In my GitLab repository, I have a group with 20 projects. I want to clone all projects at once. Is that possible?
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
An updated Python 3 script that accomplishes this really effectively using Gitlab's latest api and proper pagination:
Requires the requests library (for navigating to the page links).
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
Usage:
Also (2020): https://github.com/ezbz/gitlabber
You can refer to this ruby script here: https://gist.github.com/thegauraw/da2a3429f19f603cf1c9b3b09553728b
But you need to make sure that you have the link to the organization gitlab url (which looks like: https://gitlab.example.com/api/v3/ for example organization) and private token (which looks like: QALWKQFAGZDWQYDGHADS and you can get in: https://gitlab.example.com/profile/account once you are logged in). Also do make sure that you have httparty gem installed or
gem install httparty
In response to @Kosrat D. Ahmad as I had the same issue (with nested subgroups - mine actually went as much as 5 deep!)
Note: I use jq .projects[].http_url_to_repo this can be replaced with .ssh_url_to_repo if you'd prefer.
Alternatively strip out the rm's and look at the files individually to check the output etc.
Admittedly this will clone everything, but you can tweak it however you want.
Resources: https://docs.gitlab.com/ee/api/groups.html#list-a-groups-subgroups
Here's an example in Python 3:
I built a script (curl, git, jq required) just for that. We use it and it works just fine: https://gist.github.com/JonasGroeger/1b5155e461036b557d0fb4b3307e1e75
To find out your namespace, its best to check the API quick:
There, use "namespace.name" as
NAMESPACE
for your group.The script essentially does:
PROJECT_SEARCH_PARAM
Get their
path
andssh_url_to_repo
2.1. If the directory
path
exists, cd into it and callgit pull
2.2. If the directory
path
does not exist, callgit clone