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.
1 accepted. Hi Subhajit, there isn't a direct way to get a single file from a remote Git repository without cloning the whole repository. This is in part, because of the way that Git stores the file history internally.
Partial clone is a performance optimization that “allows Git to function without having a complete copy of the repository. The goal of this work is to allow Git better handle extremely large repositories.” Git 2.22. 0 or later is required.
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.
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