Is it possible to clone a single file from a remote repository with Git? For instance, I am looking to copy someone else's .htaccess file into my own project. I do not need their entire repository, just this one file.
-
2Possible duplicate of How to checkout only one file from git repository? – Jonathan.Brink May 20 '16 at 18:35
Rather than clone, perhaps you can simply download the file.
Assuming the repository is public, you can download a single file like this:
wget https://raw.githubusercontent.com/jquery/jquery/master/src/ajax.js
To get the url, navigate to the file in GitHub, and choose the "raw" view.
Note that this will only work with public repos.
-
Yes, I have done just that. However, I am still wondering if Git allows for such operation to be done. It would be convenient. Can wget copy directories as well? – MadPhysicist May 20 '16 at 18:34
-
@MadPhysicist Yes, it's possible. See stackoverflow.com/questions/2466735/… . I was suggesting that perhaps a tool like wget or curl may be an easier option – Jonathan.Brink May 20 '16 at 18:36
-
Should be updated to note that only works with public repos, and the OP does not specify public or private. – shellscape Jan 4 at 17:23
For Example, you want to clone this python file efficientnet_weight_update_util.py
tensorflow/tensorflow/python/keras/applications/efficientnet_weight_update_util.py
If you use the wget
tool to get the file from the link you will get the py file with HTML format so instead, use the raw version from https://raw.githubusercontent.com
and copy the URL to use it with wget
e.g.
!wget https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/python/keras/applications/efficientnet_weight_update_util.py
now you have the efficientnet_weight_update_util.py file only from the repo.