How to download individual files from GitHub enterprise

Hello,

Below instructions how to download individual files from private GitHub repository using powershell.

Assumptions:

  1. Your GitHub repository is hosted at github.mycompany.com
  2. Your organisation name is my-org
  3. Your repository name is my-repo
  4. Path to file you are trying to download is /myfiles/file.txt

Steps

  1. Obtain personal access token for you account by navigating to your account and choosing settings.
  2. Go to Personal Access Token setting and choose “Generate New Token”. Copy the resulting token key.
  3. Construct URL to the file you are trying to download in following format: http://github.mycompany.com/api/v3/repos/my-org/my-repo/contents/myfiles/file.txt
  4. Powershell script to download file is below. Values in italic are variables which will be different in your environment

Invoke-WebRequest http://github.mycompany.com/api/v3/repos/my-org/my-repo/contents/myfiles/file.txt -Headers @{“Authorization”=”token 8d795936d2c1b2806587719b9b6456bd16549ad8“;”Accept”= “application/vnd.github.v3.raw”}

If you need to download entire contents of your master branch then request will look like below

Invoke-WebRequest http://github.mycompany.com/api/v3/repos/my-org/my-repo/zipball/master -Headers @{“Authorization”=”token 8d795936d2c1b2806587719b9b6456bd16549ad8“} -OutFile out.zip

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s