How to download files and directories from github


Probably this is the easiest way to download files from github, by navigating to the file on github and click on the download button.

Unfortenitaly, it’s not the fastest, you will have to move the file to the desired destination and doesn’t work for raw files like (txt and .ext).

/posts/github-dl/github_download_page.png

Now we talk :D, here’s a bash function (add to your alias section) I wrote to automate the download process by using the URL which contains blob keyword.

Note: you know what to do to make it work with cURL :D

1
2
3
4
5
6
7
#!/bin/bash
gd () {
    SEARCH="\/blob\/"
    replace="\/raw\/"
    result=`echo $1 | sed -e "s/$SEARCH/$replace/g"`
    wget $result
}
/posts/github-dl/wget.gif

GitHub doesn’t support git-archive (a git feature to download specific folders). However, it supports a variety of Subversion features, one of which we can use. Subversion is a VC (Version Control) just like git.

Make sure you have subversion installed, for arch : sudo pacman -S subversion

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
modify_url () {
    SEARCH="\/tree\/\w\+\/"
    replace="\/trunk\/"
    echo $1 | sed -e "s/$SEARCH/$replace/g"
}

dgd () {
    url=`modify_url $1`
    svn export $url
}
/posts/github-dl/svn_github.gif