I wished to download the mysite folder from this link: https://github.com/username/repository/master/
This question is related to
git
github
ubuntu-14.04
There is a button Download ZIP
. If you want to do a sparse checkout there are many solutions on the site. For example here.
You can download the complete folder under Clone or Download options (Git URL or Download Zip)
There is a button of Download Zip
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
You have to download the whole project with either "Clone to desktop" button that will use native github program or "Download as zip".
And then search that folder in downloaded project.
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)
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
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
Use GitZip online tool. It allows to download a sub-directory of a github repository as a zip file. No git commands needed!
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.
You can use Github Contents API to get an archive link and tar
to retrieve a specified folder.
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
Source: Stackoverflow.com