DEV Community

killDevils
killDevils

Posted on • Edited on

GitHub | Download a file from a Private Repository in GitHub

I wrote a series of Bash scripts. They make my work on Google Cloud Platform (GCP) easier.

Since the PORT 25 for mail service is strictly blocked by GCP, and at the same time, building mail service on my own is quite complex. So, under Google's Suggestion, I decided to use SendGrid.

SendGrid utilizes a bot called GitGuardian to scan public repositories on GitHub, and would temporarily suspend your account if you accidentally pasted SendGrid's API key in it.

So, better save the API key in private repositories.

To download a file from private repository

1. You need to generate a Personal Access Tokens.

According to this GitHub help page:

  1. In the upper-right corner of any page, click your profile photo, then click Settings.
  2. In the left sidebar, click Developer settings.
  3. In the left sidebar, click Personal access tokens.
  4. Select the scopes. To use your token to access repositories from the command line, select repo.
  5. Click Generate new token.
  6. Give your token a descriptive name.

Let's suppose your actual token is 1234567abcdefg

2. Embed Token into the link.

  1. Open the file in GitHub web page and click "Raw"

Alt Text

  1. Copy the link of this raw file, maybe something like this:
    https:// raw.githubusercontent.com/GITHUB_ACCOUNT/REPOSITORY_NAME/BRANCH_NAME/FILE_NAME.EXTENTION_NAME?token=SOME_NUMBERS_LETTERS

  2. Reform the link as
    https:// 1234567abcdefg@raw.githubusercontent.com/GITHUB_ACCOUNT/REPOSITORY_NAME/BRANCH_NAME/FILE_NAME.EXTENTION_NAME

As you see, "?token=SOME_NUMBERS_LETTERS" are removed. Insert the token you generated from GitHub + @ right after "https://"

To use the link

curl -s -O https://1234567abcdefg@raw.githubusercontent.com/GITHUB_ACCOUNT/REPOSITORY_NAME/BRANCH_NAME/FILE_NAME.EXTENTION_NAME

Hope this would help! Cheers! 🍻

Top comments (5)

Collapse
 
afalchi82 profile image
Alessandro Falchi

Hi, is this still working? I've just tried with no success

Collapse
 
ejntaylor profile image
Elliot Taylor

Worked for me in Mar 2021

Collapse
 
bias profile image
Tobias Nickel

yes it works, just what I was looking for

Collapse
 
rpalermoteco profile image
rpalermo-teco

Doesnt work anymore. July 2023 error 404

Some comments may only be visible to logged-in visitors. Sign in to view all comments.