80

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

IamK
2,9635 gold badges36 silver badges42 bronze badges
asked Oct 11, 2015 at 15:15
4
  • 11
    Possible duplicate of Download a single folder or directory from a GitHub repo Commented Jul 21, 2017 at 9:37
  • 3
    Go to DownGit > Enter GitHub Folder URL > Download (no command, no tool, no fuss!) Commented May 13, 2020 at 15:47
  • 3
    github UI sucks. should have download folder option. Commented Dec 13, 2020 at 20:09
  • @MinhasKamal you should post that as an answer. Very useful and easy to use tool right there. Commented Jun 24, 2022 at 22:27

13 Answers 13

54

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)

answered Dec 5, 2016 at 23:22
Sign up to request clarification or add additional context in comments.

4 Comments

I had to use <repo>/branches/<branch_name>/<folder> for a non-master branch, but otherwise worked flawlessly.
<repo>/tags/<tag_name>/<folder> also seems to work
Nice, thanks. Although I haven't found how to make it work for a specific Commit-ID. Eg. the older version of CLang on MSYS2 environment: github.com/msys2/MINGW-packages/tree/…
does not work anymore
40

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
answered May 22, 2017 at 9:35

5 Comments

Nice! It's also optional with WGET, and with the regular github archive url: wget -O - https://github.com/zeit/next.js/archive/master.tar.gz | tar -xz --strip=2 "next.js-master/examples/with-apollo"
zip might works as well. wget -c https://github.com/user/project/archive/master.zip
This option is a poor one. If you only what images - it downloads whole repo first then trims it. Makes it less painful to individually download 15 images manually!
@JGFMK: maybe not rubbish, but just unclean solution which might also prove ineffective for some cases (eg. one mentioned by you: downloading several images out of hundreds).
This is just downloading the entire repo and then stripping after the fact. It's a solution sure, but not a great one
26

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

answered Feb 23, 2018 at 13:12

6 Comments

Why does it need write access to all my public repos? Isn't this a security risk?
@JaredThirsk, but it doesn't. Can you tell us when did it happen in your case?
@gdrt When I click Get Token: Normal, Github asks: "This application will be able to read and write all public repository data. This includes the following: - Code, ..."
@JaredThirsk, you should provide API Access Token if the repository isn't public. If it is public, simply providing repository URL and clicking Download button will do it.
Rare to find such an easy solution to what you want to do. This really helped me. Thanks!
|
14

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
    
answered Apr 28, 2020 at 0:15

3 Comments

The best answer of all! However, I believe there should no be "-f" in "git remote add origin", since "-f" means a immediate fetch from server, which should be avoided since only the "sparse" path is wanted!
Awesome answer!
in my case, I could see from git pull origin's verbose that doing this downloaded the entire repository; but retained only the folder specified in .git/info/sparse-checkout. and using https://downgit.github.io/ did it for me.
12

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

downloadbutton

answered Oct 11, 2015 at 15:17

5 Comments

download everything as a zip...then unzip, delete what you don't want, and rezip it and scp it to where you want it to go...
Or just simply download the whole repository and browse you desired files without installing or configuring any tool. (anyway your comment is a duplicate)
This should not be the accepted answer. To be specific, "You can't download only a folder or a file," is wrong. See below for various correct solutions.
Thank you for your suggestion, I will update the answer. I don't think the solutions below are correct, they just work. You can use git to download a sub-folder from a repository. Anyway, the repository hosting site github.com doesn't provide a way to do so without using any external tools.
Where is the Download ZIP button? On the main repository page, click on the green <> Code button. In the pop-up menu, you'll find the Download Zip option.
9

VSCode Integration for Github

Anyone like me browsing a github repository and want to download a folder from a repository from the browser, without any third party tools, you might use the vs code extensions of github.

Step 1 Open the directory of the repository which you want to download in your browser.

Step 2 In the url bar replace .com with .dev. For ex: https://github.com/lodash/lodash will become https://github.dev/lodash/lodash.

Step 3 This will open a vs code interface of that git repository. Just right click on the folder which you want to download and then press download in option.

answered Sep 6, 2022 at 4:29

1 Comment

It should be mentioned that this method works only in Chrome/Chromium-based browsers. Firefox, while supporting the GitHub web IDE "in general" doesn't provide the download function.
3

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
answered Jan 17, 2021 at 22:57

1 Comment

My vote goes to matrik. This fetch utility is exactly what I was looking for: github.com//gruntwork-io/fetch. Its a command line tool that not only fits the use case of the OP, but also provides many other useful features and switches for specifying exactly what you are after.
2

This is probably not the most efficient solution, but I think it's fun! THis downloads all the files in a folder on github just using bash

(I used this to download the files for the postgresql tutorial but haven't tested it elsewhere)

curl "https://github.com/postgres/postgres/tree/master/src/tutorial" > test.html
links=$(cat test.html | grep -o \[^\"\]\*/blob/\[^\"]\*)
echo $links
echo "Now as a list.."
as_list=($links)
for (( i=0; i<${#as_list[@]}; i++ ));do
 download_link=("https://raw.githubusercontent.com${as_list[$i]}")
 echo "completing link: "
 echo "${download_link///blob/""}"
 wget "${download_link///blob/""}"
done

Explanation:

(1)the first line downloads the target folder as an html, and saves it as test.html

(2) the second line extracts all links to files on the page. This works by observing that links to files look like "/postgres/postgres/blob/master/src/tutorial/.gitignore" on the html, we can get all those by looking for a 'blob' and getting all text upto the nearest quote " on each side

(3) we turn this into a list

(4)to finish the job, we observe that the url for the raw text version of the file looks slightly different , e.g. for the url "/postgres/postgres/blob/master/src/tutorial/.gitignore", the url for the raw text file is "https://raw.githubusercontent.com/postgres/postgres/master/src/tutorial/.gitignore". Hence to process the data we turn "/postgres/postgres/blob/master/src/tutorial/.gitignore" into "/postgres/postgres/master/src/tutorial/.gitignore", and finally into "https://raw.githubusercontent.com/postgres/postgres/master/src/tutorial/.gitignore"

P.S. sorry if my bash script is clunky - am a new linux user

answered Aug 17, 2022 at 13:55

Comments

2

You can use git archive

git archive --remote=ssh://github.com/packageName.git HEAD path/to/my/dir | tar -x
answered Mar 29, 2023 at 5:12

Comments

1

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
answered Aug 30, 2019 at 5:17

Comments

1

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

answered Apr 7, 2021 at 14:15

Comments

-3

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

answered Nov 14, 2017 at 7:25

Comments

-8

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.

Stephen Rauch
50.1k32 gold badges119 silver badges143 bronze badges
answered Oct 2, 2017 at 4:26

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.