Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download a GitLab private repository

Tags:

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.

like image 647
user3785137 Avatar asked Jun 28 '14 03:06

user3785137


1 Answers

This is possible, just follow these steps:

  1. First, you have to create a "Personal Access Token":

    1. Go to Your Profile > Settings > Access Tokens.

    2. Enter a name for your "Personal Access Token".

    3. Check "api Access the authenticated user's API"

      Personal Access Tokens

    4. Click "Create personal access token"

    5. The page will reload and save your new token.

    6. Make sure you save the token somewhere safe, you won't be able to view it again.

      New "Personal Access Token"

  2. Now that you have your "Personal Access Token", you need to get your project id to use the API:

    1. Go to https://gitlab.com/api/v4/projects?private_token=XXXXXXXXXXXXXXXXXXXX (replace the Xs with your new token)

    2. Get your project's id from the json.

      Project id

    (alternatively you can just copy Project ID from its web page)

  3. 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

like image 157
pdeschen Avatar answered Oct 13 '22 09:10

pdeschen