How can I download a specific folder from a GitHub repo? #23087
-
How can I download a specific folder or directory from a remote Git repo hosted on GitHub? I only want just that a specific folder where the files for the front-end part of the app are kept, without having the other files as I don’t really need them. |
Beta Was this translation helpful? Give feedback.
Replies: 22 comments 11 replies
-
If you are willing to use git to do this, you can do a sparse checkout. We are going to start by creating an empty git repo locally, and then add the repository we want as a remote. This allows us to easily just checkout the folder we want
After that, we want to add the directory to
(this is essentially the opposite of the gitignore file). Then we can
and it should download only the folder you want. Obviously, this requires you to use git, but it shouldn’t bee too difficult to automate if it’s something you are doing often. |
Beta Was this translation helpful? Give feedback.
-
Awesome! Thanks a lot, will definitely try this. |
Beta Was this translation helpful? Give feedback.
-
I have a specific folder from a remote Git repo that I’ve hosted on GitHub. How can I download only that one specific folder? |
Beta Was this translation helpful? Give feedback.
-
@nadiajoyce Well this question is different mine is different, I want to download a specific folder locally not on a remote Git repo I think you misunderstood my question please check it once again.I totally understand that in order to maintain forum organized you have close my question but I request you to open again since my question is different from above question. |
Beta Was this translation helpful? Give feedback.
-
If you look at the solution, it directly answers your question. The new topic you opened isn’t necessary and it is correct that people should be directed here. |
Beta Was this translation helpful? Give feedback.
-
You can try github-files-fetcher, it is a command line tool which downloads a single folder or file from a GitHub repo. Think a real scenario: you were visiting the following webpage page and wanna download the With The
|
Beta Was this translation helpful? Give feedback.
-
Thanks, @mcinkay, this was really helpful for someone who’s still learning how to use Git/GitHub. Could you elaborate on how exactly to do this part?
I’m essentially trying to download the Python-SQLite subfolder from the main code_snippets repo (see below), but I don’t know how exactly to add the directory to .git/info/sparse-checkout. Python-SQLite subfolder: https://github.com/CoreyMSchafer/code_snippets/tree/master/Python-SQLite code_snippets main repo: https://github.com/CoreyMSchafer/code_snippets Any help you can offer is greatly appreciated! |
Beta Was this translation helpful? Give feedback.
-
@gaylonalfano Edit the file and just put a line containing |
Beta Was this translation helpful? Give feedback.
-
It still downloads everything. |
Beta Was this translation helpful? Give feedback.
-
Yep, it still downloads all |
Beta Was this translation helpful? Give feedback.
-
Nope there is a change. mkdir <dir> cd <dir> git init git remote add origin -f <URL> git config core.sparseCheckout true # enable this cat >> .git/info/sparsecheckout <folder> git pull origin master Only your folder gets downloaded. This was tested on 2.13.3.windows worked fine. |
Beta Was this translation helpful? Give feedback.
-
For GitHub repos, you can clone any sub-directories of any GitHub repository (at any reference) using https://github.com/HR/github-clone |
Beta Was this translation helpful? Give feedback.
-
Hi Mclnkay, I tried your command in the Bash (MacPro Terminal), am trying to pull/clone the specific folder from Github repo (Sub-folder under repo master folder) but it did not work, please advice, thank you Alternatively, how would i be able to Copy-and-Paste a folder or file at local repo prior pull/clone its content-folder(or file) from remote Github? Thank you Thanks, Weina |
Beta Was this translation helpful? Give feedback.
-
To add to this comment (particularly if you want to turn this series of commands into a script), I would amend it as follows: mkdir <dir> cd <dir> git init git remote add origin -f <URL> git config core.sparseCheckout true # enable this echo “/absolute/path/to/folder” > .git/info/sparse-checkout # if you don’t start with root you are liable to download multiple folders wherever the name you specified is matched. git pull origin master |
Beta Was this translation helpful? Give feedback.
-
Github just need to implement https://minhaskamal.github.io/DownGit/#/home It is just one button! |
Beta Was this translation helpful? Give feedback.
-
I think the point when you do
everything is downloaded. |
Beta Was this translation helpful? Give feedback.
-
works! ty. |
Beta Was this translation helpful? Give feedback.
-
Your solution is right, but the sequence of commands didn’t work for me in Windows. My version of git has no sparse-checkout command. I am using the new PowerShell 7 command prompt https://aka.ms/powershell I never thought I’d say this of PowerShell, but it’s great! Should work in cmd too.
[url] is your remote git repo like https://github.com/hackf5/unityspy.git |
Beta Was this translation helpful? Give feedback.
-
Yes, thanks. Worked for me. But, still very slow. Not your fault! (=: Even faster:
You need to install subversion as a prerequisite. |
Beta Was this translation helpful? Give feedback.
-
Thanks (@AlMcKinlay ) for the answer. |
Beta Was this translation helpful? Give feedback.
-
Hi there, Please if you understand my problem, I just need an example working code to follow and do mine. Please any solution? |
Beta Was this translation helpful? Give feedback.
If you are willing to use git to do this, you can do a sparse checkout.
We are going to start by creating an empty git repo locally, and then add the repository we want as a remote. This allows us to easily just checkout the folder we want
After that, we want to add the directory to
(this is essentially the opposite of the gitignore file).
Then we can
and it should download only the folder you want.
Obviously, this requires you to use git, but it shouldn’t bee too difficult to automate if it’s something you are doing often.