How to download a folder from github?

GitGithubUbuntu 14.04

Git Problem Overview


I wished to download the mysite folder from this link: https://github.com/username/repository/master/

Git Solutions


Solution 1 - Git

You can download a file/folder from github

Simply use: svn export <repo>/trunk/<folder>

Ex: svn export https://github.com/lodash/lodash/trunk/docs

Note: You may first list the contents of the folder in terminal using svn ls <repo>/trunk/folder

(yes, that's svn here. apparently in 2016 you still need svn to simply download some github files)

Solution 2 - Git

You can use Github Contents API to get an archive link and tar to retrieve a specified folder.

###Command line:

> curl https://codeload.github.com/***[owner]***/***[repo]***/tar.gz/master |
tar -xz --strip=2 [repo]-master/[folder_path]


For example,
if you want to download examples/with-apollo/ folder from zeit/next.js, you can type this:

curl https://codeload.github.com/zeit/next.js/tar.gz/master | \
  tar -xz --strip=2 next.js-master/examples/with-apollo

Solution 3 - Git

Use GitZip online tool. It allows to download a sub-directory of a github repository as a zip file. No git commands needed!

Solution 4 - Git

There is a button Download ZIP. If you want to do a sparse checkout there are many solutions on the site. For example here.

Solution 5 - Git

How to download a specific folder from a GitHub repo

Here a proper solution according to this post:

  • Create a directory

     mkdir github-project-name 
     cd github-project-name
    
  • Set up a git repo

     git init
     git remote add origin <URL-link of the repo>
    
  • Configure your git-repo to download only specific directories

     git config core.sparseCheckout true # enable this
    
  • Set the folder you like to be downloaded, e.g. you only want to download the doc directory from https://github.com/project-tree/master/doc

     echo "/absolute/path/to/folder" > .git/info/sparse-checkout 
    

    E.g. if you only want to download the doc directory from your master repo https://github.com/project-tree/master/doc, then your command is echo "doc" > .git/info/sparse-checkout.

  • Download your repo as usual

     git pull origin master
    

Solution 6 - Git

Dependency: cURL and 7-Zip.

curl {url for downloading zip file} | 7z a -tzip {project name}-{branch name}/{folder path in that branch}

for example:

curl https://github.com/hnvn/flutter_shimmer/archive/master.zip | 7z a -tzip flutter_shimmer-master/examples

Solution 7 - Git

If you want to automate the steps, the suggestions here will work only to an extent.

I came across this tool called fetch and it worked quite fine for me. You can even specify the release. So, it takes a step to download and set it as executable, then fetch the required folder:

curl -sSLfo ./fetch \
https://github.com/gruntwork-io/fetch/releases/download/v0.3.12/fetch_linux_amd64
chmod +x ./fetch
./fetch --repo="https://github.com/foo/bar" --tag="${VERSION}" --source-path="/baz" /tmp/baz

Solution 8 - Git

There exists also a nice browser extension which allows to dl files or folders

Solution 9 - Git

You can download the complete folder under Clone or Download options (Git URL or Download Zip)

  1. There is a button of Download Zip

  2. By using command you can download the complete folder on your machine but for that you need git on your machine. You can find the Git url uner

    git clone https://github.com/url

Solution 10 - Git

You can also just clone the repo, after cloning is done, just pick the folder or vile that you want. To clone:

git clone https://github.com/somegithubuser/somgithubrepo.git

then go to the cloned DIR and find your file or DIR you want to copy.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGangeshView Question on Stackoverflow
Solution 1 - GitAnona112View Answer on Stackoverflow
Solution 2 - GitchuyikView Answer on Stackoverflow
Solution 3 - GitgdrtView Answer on Stackoverflow
Solution 4 - GitC1sc0View Answer on Stackoverflow
Solution 5 - Gitabu_buaView Answer on Stackoverflow
Solution 6 - GitKalpesh KundananiView Answer on Stackoverflow
Solution 7 - GitmatrikView Answer on Stackoverflow
Solution 8 - Gitabu_buaView Answer on Stackoverflow
Solution 9 - GitVIKAS KOHLIView Answer on Stackoverflow
Solution 10 - Gituser2963512View Answer on Stackoverflow