Skip to content

Instantly share code, notes, and snippets.

@twglomski
Created April 11, 2017 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twglomski/81878398b3c6bf6a85facd76de4cd390 to your computer and use it in GitHub Desktop.
Save twglomski/81878398b3c6bf6a85facd76de4cd390 to your computer and use it in GitHub Desktop.
Returning the content of a text file from a private repository on GitHub
Git is good at grabbing entire repositories, but what if you just want a single file in a private repo? This snippet, given a path, will grab a download url for a given file, then download it.
Prereqs:
1. You have a personal access token saved as github_access_token.key. To get a personal access token, go here: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
2. jq is installed (On ubuntu: apt-get install jq)
Replace the path of "PrivateOrg/PrivateRepo" with the path to the private repo of your choice, and "/subfolder/targetfile.py" with the file path to the desired file inside the private repo.
curl -H "Authorization: token $(cat github_access_token.key)" $(curl -H "Authorization: token $(cat github_access_token.key)" https://api.github.com/repos/PrivateOrg/PrivateRepo/contents/subfolder/targetfile.py | jq '.download_url' -r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment