Created
April 11, 2017 21:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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