Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning a Single File from Github Repo

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.

like image 518
MadPhysicist Avatar asked May 20 '16 18:05

MadPhysicist


People also ask

Can I clone a single file from git?

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.

Can you clone only part of a repository?

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.


Video Answer


1 Answers

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.

like image 120
Jonathan.Brink Avatar answered Oct 21 '22 18:10

Jonathan.Brink