Search code examples
gitgithubversion-controlgit-clone

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.


Solution

  • 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.