GitHub lets you download one file from a repository. This is a useful feature because it means you do not have to clone or retrieve an entire repository to download a particular file. You cannot retrieve a single file using the git command line, even if your repository is hosted on GitHub.
You can't clone a single file using git. Git is a distributed version control system, the Idea behind its clone functionality is to have a complete copy of project and all versions of files related to that project.
In git version 1.7.9.5 this seems to work to export a single file from a remote
git archive --remote=ssh://host/pathto/repo.git HEAD README.md
This will cat the contents of the file README.md
.
Following on from Jakub's answer. git archive
produces a tar or zip archive, so you need to pipe the output through tar to get the file content:
git archive --remote=git://git.foo.com/project.git HEAD:path/to/directory filename | tar -x
Will save a copy of 'filename' from the HEAD of the remote repository in the current directory.
The :path/to/directory
part is optional. If excluded, the fetched file will be saved to <current working dir>/path/to/directory/filename
In addition, if you want to enable use of git archive --remote
on Git repositories hosted by git-daemon, you need to enable the daemon.uploadarch config option. See https://kernel.org/pub/software/scm/git/docs/git-daemon.html
If there is web interface deployed (like gitweb, cgit, Gitorious, ginatra), you can use it to download single file ('raw' or 'plain' view).
If other side enabled it, you can use git archive's '--remote=<URL>
' option (and possibly limit it to a directory given file resides in), for example:
$ git archive [email protected]:foo/bar.git --prefix=path/to/ HEAD:path/to/ | tar xvf -
Not in general but if you are using Github:
For me wget
to the raw url turned out to be the best and easiest way to download one particular file.
Open the file in the browser and click on "Raw" button. Now refresh your browser, copy the url and do a wget
or curl
on it.
wget example:
wget 'https://github.abc.abc.com/raw/abc/folder1/master/folder2/myfile.py?token=DDDDnkl92Kw8829jhXXoxBaVJIYW-h7zks5Vy9I-wA%3D%3D' -O myfile.py
Curl example:
curl 'https://example.com/raw.txt' > savedFile.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With