This is a quick script which uses Gitlab APIs to list every project that a low privilege user has access to and either clone the repo or pull (to update changes). It has the effect of allowing you to easily keep a local copy up to date of every repo in an organisation.
If any project has a wiki, it will clone that too.
To get an API token, you need to:
- Log into gitlab.
- Go to User Settings/Access Tokens (
/-/user_settings/personal_access_tokens
) - Create an access token which needs
read_api
Essentially, the code performs the following steps:
- Use the API to list the first page of projects that this token has access to
- Go through each project and either git clone or git pull. This works by adding the request to a concurrent pool which runs in multiple threads.
- Use the API to see if the wiki exists for that project. If so, git clone/git pull that too.
- Use the API to go to the next page and continue.
If you want to use HTTPS rather than SSH, change the code to use the https url. You would need to have an SSH key that works too, e.g. using ssh-agent.
In other words, ssh_url_to_repo
needs to change to http_url_to_repo
.
Probably, and you'll need to customise the code if you want to do anything different.
Checkout everything I have access to on https://git.boat.internal and store it in /usr/home/stuart/git-org (API token: glpat-ssHXnCabQjFhQier_A4)
$ ./getgit.py -t glpat-ssHXnCabQjFhQier_A4 -u https://git.boat.internal -d /usr/home/stuart/git-org
Checkout everything I have access to on https://git.boat.internal and store it in /usr/home/stuart/git-org and suppress SSH banner (API token: glpat-ssHXnCabQjFhQier_A4)
$ GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=error" ./getgit.py -t glpat-ssHXnCabQjFhQier_A4 -u https://git.boat.internal -d /usr/home/stuart/git-org
Further help
./getgit.py -h