How to retrive a single file from github using git
Solution 1
You can get that file using wget
:
-
Create a directory:
mkdir mypycode
-
Change into that directory:
cd mypycode
-
Identify the raw URL
- Navigate to your file on github (or your git host)
- Click on the Raw tab.
-
Use
wget
to download it:wget https://raw.githubusercontent.com/tensorflow/tensorflow/r1.1/tensorflow/examples/tutorials/mnist/mnist_softmax.py
Solution 2
I suggest the following command :
git archive [email protected]:foo/bar.git HEAD | tar xvf - path/to
Solution 3
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.
Either download your file directly from here or clone the whole project using:
clone https://github.com/tensorflow/tensorflow.git
Also from here:
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=' 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 -
Related videos on Youtube
J.Doe
Updated on September 18, 2022Comments
-
J.Doe over 1 year
I would like to learn more about this code, but I am not able to import it into my computer. How could I clone this file with git? The file is simply:
https://github.com/tensorflow/tensorflow/blob/r1.1/tensorflow/examples/tutorials/mnist/mnist_softmax.py.
Thanks!
-
omerfarukdogan about 7 yearsIs there a reason you don't download it from the website?
-
-
Ravexina about 7 yearsYou are downloading the html file, you should change it to raw version ;)
-
J.Doe about 7 yearsThanks for the answer. I did not know that.
-
Ravexina about 7 years;) Just for note:
wget
is a download manager, just likecurl
,aria2
,axel
,firefox
download manager, or anything else :) -
J.Doe about 7 yearsWhat are the difference between those download manager?
-
Ravexina about 7 yearsOptions and capabilities; With the accepted instruction, you are downloading the same file as I said with a different tool ...
-
nhed almost 6 yearsthis is github centric, OP asked about using
git
-
x-yuri over 5 yearsYou might want to make use of
tar
's switches--strip-components
or--transform
.