How to retrive a single file from github using git

87,685

Solution 1

You can get that file using wget:

  1. Create a directory:

     mkdir mypycode
    
  2. Change into that directory:

     cd mypycode
    
  3. Identify the raw URL

  • Navigate to your file on github (or your git host)
  • Click on the Raw tab.
  1. 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 -

Share:
87,685

Related videos on Youtube

J.Doe
Author by

J.Doe

Updated on September 18, 2022

Comments

  • J.Doe
    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
      omerfarukdogan about 7 years
      Is there a reason you don't download it from the website?
  • Ravexina
    Ravexina about 7 years
    You are downloading the html file, you should change it to raw version ;)
  • J.Doe
    J.Doe about 7 years
    Thanks for the answer. I did not know that.
  • Ravexina
    Ravexina about 7 years
    ;) Just for note: wget is a download manager, just like curl, aria2, axel, firefox download manager, or anything else :)
  • J.Doe
    J.Doe about 7 years
    What are the difference between those download manager?
  • Ravexina
    Ravexina about 7 years
    Options and capabilities; With the accepted instruction, you are downloading the same file as I said with a different tool ...
  • nhed
    nhed almost 6 years
    this is github centric, OP asked about usinggit
  • x-yuri
    x-yuri over 5 years
    You might want to make use of tar's switches --strip-components or --transform.