For gitlab, if I get the client_id and client_secret, how can I clone the repository, just like what drone does. Is there any API or something?
Asked
Active
Viewed 476 times
1 Answers
0
The is no "GitLab API" for cloning, since git clone
native command is there for that.
You could then try and clone with:
git clone https://oauth2:TOKEN@ANY_GIT_PROVIDER_DOMAIN/YOUR_PROJECT/YOUR_REPO.git
(assuming the client_secret
is the token)
Or:
git clone https://client_id:TOKEN@ANY_GIT_PROVIDER_DOMAIN/YOUR_PROJECT/YOUR_REPO.git
(replace client_id by the actual value)
However, this is considered bad practice, and Git 2.37 (Q3 2022) will display the warning:
URL '%s' uses plaintext credentials
It is better to cache those credentials:
git config --global credential.helper
xxx <= note that value
printf "host=gitlab.com\nprotocol=https\nusername=client_d\npassword=client_secret" | \
git credential-xxx store
(replace xxx
, client_id
and client_secret
by their actual values)
And then
git clone https://client_id@ANY_GIT_PROVIDER_DOMAIN/YOUR_PROJECT/YOUR_REPO.git
No more token/secret in the URL.

VonC
- 1,262,500
- 529
- 4,410
- 5,250