I want to use curl
to download my private repo in GitLab. I know I can use the Gitlab API, but for some reason, It doesn't work.
Is this possible? When I try to do it this way, it always returns the login page.
This is possible, just follow these steps:
First, you have to create a "Personal Access Token":
Go to Your Profile > Settings > Access Tokens.
Enter a name for your "Personal Access Token".
Check "api Access the authenticated user's API"
Click "Create personal access token"
The page will reload and save your new token.
Make sure you save the token somewhere safe, you won't be able to view it again.
Now that you have your "Personal Access Token", you need to get your project id to use the API:
Go to https://gitlab.com/api/v4/projects?private_token=XXXXXXXXXXXXXXXXXXXX (replace the Xs with your new token)
Get your project's id from the json.
(alternatively you can just copy Project ID from its web page)
Now you can call:
wget -O your_project.tar.gz https://gitlab.com/api/v4/projects/0000000/repository/archive?private_token=XXXXXXXXXXXXXXXXXXXX
And that'll download your project as a .tar.gz
file.
Edit: you can get tarball for specific commit/tag by adding &sha=...
parameter to URL, like: https://gitlab.com/api/v4/projects/24470128/repository/archive?private_token=XXXXXXXXXXXXX&sha=606e81c69eff27eccbbc59a0546a9439780dff55
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With