Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Pilot Lvl 1
Message 1 of 13

How can I download a specific folder from a GitHub repo?

Solved! Go to Solution.

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.

12 Replies
Solution
Copilot Lvl 3
Message 2 of 13

Re: How can I download a specific folder from a GitHub repo?

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

 

mkdir directoryName
cd directoryName
git init
git remote add origin -f repoUrl

 

 

After that, we want to add the directory to 

.git/info/sparse-checkout

(this is essentially the opposite of the gitignore file).

 

 

Then we can 

git pull origin master

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.

Pilot Lvl 1
Message 3 of 13

Re: How can I download a specific folder from a GitHub repo?

Awesome! Thanks a lot, will definitely try this.

Copilot Lvl 2
Message 4 of 13

Re: How can I download a specific folder from a GitHub repo?

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?

 


After that, we want to add the directory to 

.git/info/sparse-checkout

(this is essentially the opposite of the gitignore file).

 


 

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!

 

Copilot Lvl 3
Message 5 of 13

Re: How can I download a specific folder from a GitHub repo?

@gaylonalfano Edit the file and just put a line containing `Python-SQLite` The syntax is the same the gitignore file .

Ground Controller Lvl 1
Message 6 of 13

Re: How can I download a specific folder from a GitHub repo?

It still downloads everything.

Ground Controller Lvl 1
Message 7 of 13

Re: How can I download a specific folder from a GitHub repo?

Yep, it still downloads all

Ground Controller Lvl 1
Message 8 of 13

Re: How can I download a specific folder from a GitHub repo?

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.

Copilot Lvl 2
Message 9 of 13

Is it possible to download only one folder from a remote Git repo?

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?

Copilot Lvl 3
Message 10 of 13

Re: How can I download a specific folder from a GitHub repo?

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