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

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.

14 Replies
Solution
Copilot Lvl 3
Message 2 of 15

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 15

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 15

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 15

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 15

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

It still downloads everything.

Ground Controller Lvl 1
Message 7 of 15

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

Yep, it still downloads all

Ground Controller Lvl 1
Message 8 of 15

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.

Mission Specialist Lvl 1
Message 9 of 15

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

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

Ground Controller Lvl 2
Message 10 of 15

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

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