Copy the specific file's raw link from GitHub.(As you open the file in Github, on the top right corner you can see the option to open the file in raw mode. Open it in raw mode and copy the URL)
Now use curl or wget command in command line to download the file.
curl -o filename raw-link-to-file
or
wget -O filename raw-link-to-file
Please note that
Answer from mental_matrix on Stack OverflowCopy the specific file's raw link from GitHub.(As you open the file in Github, on the top right corner you can see the option to open the file in raw mode. Open it in raw mode and copy the URL)
Now use curl or wget command in command line to download the file.
curl -o filename raw-link-to-file
or
wget -O filename raw-link-to-file
Please note that
If you go to the page and view the links provided by "raw" (in the top left corner, when viewing the file). You will see, that you can access it by:
https://github.com/username/repository/raw/$changeset_hash/path/to/file
Instead of $changeset_hash you can also provide a branch (e.g. master) or tag.
You can retrieve the raw file using something like wget.
Accessing a single file directly from a .git-repository is not possible (as far as I know), because of how the data is stored.
edit: When you want to access a file from a private repo, you first have to create an access token with the appropriate permissions in your account settings. Instead of calling the url above you can then use github's API to access the content of a file. Be sure to use the Accept-header for custom media types to get the raw data. This might look something like this:
curl \
-H 'Authorization: token $YOUR_TOKEN' \
-H 'Accept: application/vnd.github.v3.raw' \
-O \
-L 'https://api.github.com/repos/:owner/:repo/contents/:path'
The -O will save the contents in a local file with the same name as the remote file name. For easier use you can wrap it in a script. @Chris_Withers suggested an edit with a nice python snippet that unfortunately got rejected as to big of a change to the answer.
The shortest way that seems to be what you want would be git clone https://github.com/user/repository --depth 1 --branch=master ~/dir-name. This will only copy the master branch, it will copy as little extra information as possible, and it will store it in ~/dir-name.
This will clone the files into new directory it creates:
git clone [email protected]:whatever NonExistentNewFolderName
Downloading Stuff from GitHub in Linux Command Line - Tutorials & Resources - It's FOSS Community
How to download/clone a program from github?
github - how can i download code from git hub using command line - Stack Overflow
Plain and simple: How to download files from github?
I can't find the installation zip file. What do I do?
If you've installed the files and can't find an important one, like an installation file, go back to the GitHub page where you downloaded the data. Click the Issue tab and click New Issue.
Let the developer know you're missing a file and they should respond.
How do I know which files are safe to download?
GitHub is merely an online repository meaning people can upload whatever code they'd like for you to download. It's best to be leery before downloading anything from GitHub. But there are some indicators that the files are trustworthy.
Check the number of stars, number of contributors, and new releases. If the contributors maintain the software and it has good ratings (from a lot of people), it's likely safe.
Videos
First of all, curl says "bad/illegal format" because you're mixing the URL-style and rsh-style address formats. Traditionally, Git accepts both for git clone, but only the latter puts a : between host and path – whereas in URLs, all paths start with a /. For example, the rsh/scp-style address [email protected]:foo/bar would be written as the URL ssh://[email protected]/foo/bar, just like HTTP URLs.
SSH is not a file transfer protocol on its own – it's more like TLS, something that can carry various file transfer protocols such as SFTP or scp or rsync (much like TLS can carry HTTP). Giving curl an ssh:// URL is meaningless1, but you could give it an sftp:// one to retrieve a file over SFTP. (Note how the article that you linked also specifically uses SFTP.)
However, GitHub does not provide SFTP access; the only thing allowed over SSH connections to GitHub is the Git protocol. That's not something you can access with curl, only with git clone.
So if you must use SSH, then your only option with GitHub is to actually clone the repository via Git. (It is possible to reduce the download size using --depth= or --filter= options, but it still ends up being a whole repository and not just the individual file.)
1 (Git uses ssh:// URLs but the meaning is clear from context – it's the Git protocol, but tunnelled over SSH. Git doesn't use SFTP.)
first of all you need a API access token from github how to create it:
- go to github.com and click on your profile picture at top right
- scroll down and click settings on the side bar which is shown
- scroll down and click on developer settings on left sidebar
- click on Personal Access Token(menu bar)
- click on tokens(classic)
- then click on Generate New Token(menu bar)
- then click on generate new token(classic)
- write the information of the token(name, expires date) and be careful! allow all of the access which is shown on the page! if you don't the API shouldn't work
- copy your API key
- write this code with the token you got copy
import requests
from requests.structures import CaseInsensitiveDict
GH_PREFIX = "https://raw.githubusercontent.com"
ORG = "GITHUB_USERNAME"
REPO = "YOUR_REPOSITORY_NAME"
BRANCH = "YOUR_REPOSITORY_BRANCH"
FOLDER = "THE_FOLDER_WHICH_INCLUDE_TEST.txt"
FILE = "THE_FILE_YOU_WANT_TO_ACCESS(TEST.txt)"
url = GH_PREFIX + "/" + ORG + "/" + REPO + "/" + BRANCH + "/" + FOLDER + "/" + FILE
headers = CaseInsensitiveDict()
headers["Authorization"] = "token " + "YOUR_API_ACCESS_TOKEN_HERE"
r = requests.get(url, headers=headers, stream=True)
first = str(r.content).replace("b'", "")
second = first.replace("\\r", "")
third = second.replace("\\n'", "")
result = third.replace("'", "")
print(result)
i hope this helps you
It does work, if you use the correct URL.
For a GitHub repo, there's a zip at https://github.com/<user>/<repo>/archive/<branch>.zip, so you can download it with:
wget https://github.com/<user>/<repo>/archive/<branch>.zip
This downloads the zipped repo for a given branch. Note that you can also replace the branch by a commit hash.
Using cURL
curl -L -O https://github.com/<user>/<repo>/archive/<branch>.zip
cURL's -L flag follows redirects - it's a default in wget. -O is advised by Phil Gibbins in a comment.
Download a .tgz instead of .zip
You can also download a tarball with:
wget https://github.com/<user>/<repo>/archive/<branch>.tar.gz
From the comments I saw you actually speak about GitHub.
It won't work like this because:
Downloading a project on GitHub causes the GitHub server to first pack your project as zip and than forwarding you to a temporary link where you get your zip ..
this link will only work for a certain time and than GitHub will delete your zip file from their servers..
So what you get with wget is just the html page which would forward you as soon as your zip file is generated.
As suggested use
git clone http://github.com/<yourRepoLink> <optional local path where to store>
to download the git repo ... If for some reason (e.g. for transfer it to others) you need it explicitly as zip you still could pack it after cloning is finished..
so, i used this program on another computer and now i could only find it to download on github, but i'm newbie on github, could someone teach me how to clone/download it? thanks.
Edit: I'm on windows