WIP
git-group-cloner
is a script for cloning all projects in a GitLab or GitHub group while preserving the subgroups structure or flattening it. The script provides a convenient way to manage and backup all your projects in a single group.
- Clone all projects in a GitLab or GitHub group.
- Preserve the subgroups structure or flatten it.
- Pass arguments to
git clone
to control the cloning process. - Specify the destination directory for cloning projects.
- Parallel cloning (up to 4 times faster) using either
xargs
orrargs
. - Support for custom values for
GITLAB_BASE_URL
andGITHUB_BASE_URL
. - POSIX-compliant.
jq
: a lightweight and flexible command-line JSON processor.git
: a distributed version control system.xargs
orrargs
(optional): a tool for building and executing command lines from standard input.
Before you can use git-group-cloner
, you need to set the TOKEN
environment variable. This variable is used to authenticate with the GitLab or GitHub API.
To set the TOKEN
environment variable, you can use the following command:
export TOKEN=<private_token>
Replace <private_token>
with your private token or access token. You can obtain a private token or access token from the GitLab or GitHub website (see the FAQ).
Once you have set the TOKEN
environment variable, you can use git-group-cloner
to clone projects. For more information on using git-group-cloner
, see the Usage section.
git-group-cloner [platform] [list|clone] [--flatten] [--git-args <git-arguments>] [--dest-dir <destination_directory>] [--threads <number_of_threads>] [--use-ssh]
platform
: the platform to use (gitlab
orgithub
).list
: list the group IDs and names.clone
: clone all projects in the group.--flatten
: flatten the subgroups structure.--git-args <git-arguments>
: pass arguments togit clone
.--dest-dir <destination_directory>
: specify the destination directory for cloning projects.--threads <number_of_threads>
: specify the number of cloning threads (default: 4).--use-ssh
: Switch the cloning method from the default HTTPS to SSH.
git-group-cloner gitlab list
git-group-cloner github clone <group_id>
git-group-cloner gitlab clone --flatten <group_id>
git-group-cloner github clone --dest-dir ~/projects <group_id>
git-group-cloner gitlab clone --git-args "--depth 1 --branch dev" <group_id>
git-group-cloner github clone --threads 2 <group_id>
export GITLAB_BASE_URL=https://my-gitlab.com
git-group-cloner gitlab clone <group_id>
export GITHUB_BASE_URL=https://api.my-github-enterprise.com
git-group-cloner github clone <group_id>
git-group-cloner
provides a convenient way to clone all projects in a GitLab or GitHub group while preserving the subgroups structure or flattening it. It also allows you to pass arguments to git clone
to control the cloning process and specify the destination directory for cloning projects. With git-group-cloner
, you can easily manage and backup all your projects in a single group.
gitlab
and github
are different platforms that host Git repositories. gitlab
is a GitLab instance, while github
is a GitHub organization. git-group-cloner
supports both platforms and allows you to clone all projects in a group on either platform.
You can get your private token from your GitLab account settings. Go to your profile settings, then access the "Access Tokens" section, and create a new token with the desired scope.
You can get your access token from your GitHub account settings. Go to your settings, then access the "Developer settings", and click on "Personal access tokens". Create a new token with the desired scope.
jq
is a command-line JSON processor. You can download it from the jq website. On Linux, you can also install it using your package manager, for example:
sudo apt install jq
rargs
is a tool written in Rust for parallelizing the execution of shell commands.
git-group-cloner
uses rargs
to parallelize the cloning of projects, which can significantly speed up the cloning process.
If rargs
is not found, git-group-cloner
will fallback to using xargs
or cloning one by one, depending on the availability of xargs
.
See the rargs
README for installation instructions.
To clone all projects in a group, you need to specify the platform (gitlab
or github
) and the group ID or group name. You can also specify the subgroups structure (flatten or preserve), pass arguments to git clone
, specify the destination directory for cloning projects, and specify the number of cloning threads.
For example, to clone all projects in a GitLab group, you can use the following command:
git-group-cloner gitlab clone <group_id>
To preserve the subgroups structure, you don't need to do anything special. The default behavior of git-group-cloner
is to preserve the subgroups structure.
For example, to clone all projects in a GitLab group and preserve the subgroups structure, you can use the following command:
git-group-cloner gitlab clone <group_id>
To flatten the subgroups structure, you need to specify the --flatten
option.
For example, to clone all projects in a GitLab group and flatten the subgroups structure, you can use the following command:
git-group-cloner gitlab clone --flatten <group_id>
To specify the destination directory for cloning projects, you need to use the --dest-dir <destination_directory>
option.
For example, to clone all projects in a GitLab group and specify the destination directory, you can use the following command:
git-group-cloner gitlab clone --dest-dir ~/projects <group_id>
To pass arguments to git clone
, you need to use the --git-args <git-arguments>
option.
For example, to clone all projects in a GitLab group and pass arguments to git clone
, you can use the following command:
git-group-cloner gitlab clone --git-args "--depth 1 --branch dev" <group_id>
To specify the number of cloning threads, you need to use the --threads <number_of_threads>
option. By default, git-group-cloner
uses 4 cloning threads.
For example, to clone all projects in a GitLab group and specify 2 cloning threads, you can use the following command:
git-group-cloner gitlab clone --threads 2 <group_id>
To use custom values for GITLAB_BASE_URL
and GITHUB_BASE_URL
, you need to set the environment variables GITLAB_BASE_URL
and GITHUB_BASE_URL
before running git-group-cloner
.
For example:
export GITLAB_BASE_URL=https://my-gitlab.com/api/v4/groups
git-group-cloner gitlab clone <group_id>
or:
env GITHUB_BASE_URL=https://api.my-git.luolix.top/orgs git-group-cloner github clone <group_id>
This allows you to use custom instances of GitLab and GitHub, rather than the default instances at https://gitlab.com
and https://github.com
, respectively.
If you find a bug or have an idea for a new feature, feel free to open an issue or submit a pull request. We welcome all contributions to git-group-cloner
!
git-group-cloner
is licensed under the MIT License. See the LICENSE file for more information.