Automate the cloning of your GitLab repositories and optionally push them to GitHub with these Bash scripts.
So you have gazillions of repositories on Gitlab( and you don't want to use the glab func below), and for some reason, you need to download them all and perhaps push them to GitHub (I don't know why, but people do crazy things); you are at the right place. This repository contains two Bash scripts that automate the process of cloning your repositories from GitLab and then pushing them to GitHub.
- GitLab Personal Access Token: Required for cloning repositories from your GitLab account.
- GitHub Personal Access Token: Required for creating new repositories in your GitHub account.
curl
,jq
, andgh
must be installed.
This script clones all your repositories from your GitLab account and pushes them to your GitHub account. The GitLab API uses pagination, and by default, it returns 20 items per page. Even if you set per_page to 100, you'll only get the first 100 projects. so what we do is :
- First, determine the number of pages of projects you have. This can be found in the X-Total-Pages header of the GitLab API response.
- Loop over each page and retrieve the projects.
-
Make the script executable:
chmod +x clone_all_gitlab.sh
-
Open
clone_all_gitlab.sh
and replaceTOKEN
with your actual GitLab token. -
Run the script:
./clone_all_gitlab.sh
This script clones all repositories from your GitLab account (even if they are more than 100 due to pagination) and pushes them to your GitHub account.
-
Make the script executable:
chmod +x clone_all_gitlab_pust_to_Github.sh
-
Open
clone_all_gitlab_pust_to_Github.sh
and replaceYOUR_GITLAB_TOKEN
,YOUR_GITHUB_TOKEN
, andyour_github_username
with your actual tokens and GitHub username. -
Run the script:
./clone_all_gitlab_pust_to_Github.sh
Caution: These scripts will create a lot of repositories in your GitHub account based on your GitLab account. Make sure you want to proceed before running the scripts.
- Fetches repositories from GitLab.
- Creates corresponding private repositories on GitHub.
- Pushes the code from your GitLab repositories to your GitHub repositories.
##glab upload your public certificate to your gitlab profile then run
eval "$(ssh-agent -s)" (run the agent)
ssh-add ~/.ssh/id_rsa (or wherever the ssh is located)
glab repo clone -g project_id -p --paginate