I want to import single function from
lodash
while preserving typings. Such as this:But it seems that I cannot do so. Compiler says that there is no module
lodash/invokeMap
. It's correct — DefinitelyTyped declares only top-level module for lodash
, so I can import only the whole package. But I want to import only one function.Learn Git and GitHub basics. Download the latest. Learn Lo-Dash (fork of underscore) to handle your arrays and objects simple! Npm install -g lololodash.
Is there a way to import only typings information about lodash without importing lodash itself?
Below is my workaround plan. I want to use standard CommonJS
require
function to import the necessary function without types information and then cast type onto it:GirafaGirafa
3 Answers
With the current typings lodash this should work as you tried it before:
just install a current version of the ambient dependencies like so:
svi3csvi3c
As of TypeScript 2, you can install typings directly from npm:
npm install @types/lodash
Those typings have declarations for each individual module.
Muhammad Fawwaz OrabiMuhammad Fawwaz Orabi
You can use object destructuring to import only the invokeMap function from the module.
toskvtoskv
Not the answer you're looking for? Browse other questions tagged typescriptlodashdefinitelytyped or ask your own question.
How can I download only a specific folder or directory from a remote Git repo hosted on GitHub?
Say the example GitHub repo lives here:
Its directory structure:
I want to download only the foo folder and not clone the whole Test project.
g_inheritg_inherit
28 Answers
Update Sep. 2016: there are a few tools created by the community that can do this for you:
- GitZip (Credits to Kino - upvote his answer right here!)
- DownGit (Credits to Minhas Kamal - upvote his answer right here!)
Git doesn't support this, but Github does via SVN. If you checkout your code with subversion, Github will essentially convert the repo from git to subversion on the backend, then serve up the requested directory.
Here's how you can use this feature to download a specific folder. I'll use the popular javascript library
lodash
as an example.- Get the repo URL. First, copy the URL of the Github repo to your clipboard.
- Modify the URL for subversion. I want to download the folder at
/docs
from themaster
branch, so I will appendtrunk/docs
. Full URL is nowhttps://github.com/lodash/lodash/trunk/docs
. See my note below for a more in-depth explanation of why we must use this URL format. - Download the folder. Go to the command line and grab the folder with SVN.
svn checkout https://github.com/lodash/lodash/trunk/docs
You might not see any activity immediately because Github takes up to 30 seconds to convert larger repositories, so be patient.
Full URL format explanation:
- If you're interested in
master
branch, usetrunk
instead. So the full path istrunk/foldername
- If you're interested in
foo
branch, usebranches/foo
instead. The full path looks likebranches/foo/foldername
- Protip: You can use
svn ls
to see available tags and branches before downloading if you wish
That's all! Github supports more subversion features as well, including support for committing and pushing changes.
nicknick
Two options for this feature:
Option 1: Browser Extensions
Chrome Extension, Firefox Addon
Usage:
- In any GitHub repos page.
- Just double click on the items you need.
- Click download button at bottom-right.
- See the progress dashboard and wait for browser trigger download.
- Get the ZIP file.
Get Token:
- Click GitZip Extension icon on your browser.
- Click 'Normal' or 'Private' link besides 'Get Token'.
- Authorize GitZip permission on Github auth page.
- Back to repo page of the beginning.
- Continue to use.
Option 2: Github gh-page
http://kinolien.github.io/gitzip by using GitHub API, and JSZip, FileSaver.js libraries.
Step1: Input github url to the field at the top-right.
Step2: Press enter or click download for download zip directly or click search for view the list of sub-folders and files.
Step3: Click 'Download Zip File' or 'Get File' button to get files.
Step2: Press enter or click download for download zip directly or click search for view the list of sub-folders and files.
Step3: Click 'Download Zip File' or 'Get File' button to get files.
In most cases, it works fine, except that the folder contains more than 1,000 files, because of the Github Trees API limitation. (refers to Github API#Contents)
And it also can support private/public repos and upgrade the rate limit, if you have GitHub account and use 'get token' link in this site.
KinoKino
Now, you can DIRECTLY DOWNLOAD or create DOWNLOAD LINK for any GitHub public directory or file (specially large file) from DownGit! Here is a simple demonstration-
You may also configure the downloaded file's property- detailed usage.
Minhas KamalMinhas Kamal
If you have
svn
, you can use svn export
to do this:Notice the URL format:
- The base URL is
https://github.com/
/trunk
appended at the end
Before you run
svn export
, it's good to first verify the content of the directory with:janosjanos
For a Generic git Repo:
If you want to download files, not clone the repository with history, you can do this with
git-archive
.git-archive
makes a compressed zip or tar archive of a git repository. Some things that make it special:- You can choose which files or directories in the git repository to archive.
- It doesn't archive the
.git/
folder, or any untracked files in the repository it's run on. - You can archive a specific branch, tag, or commit. Projects managed with git often use this to generate archives of versions of the project (beta, release, 2.0, etc.) for users to download.
An example of creating an archive of the
docs/usage
directory from a remote repo you're connected to with ssh:More information in this blog post and the git documentation.
Note on GitHub Repos:
GitHub doesn't allow
git-archive
access. ☹️RobWRobW
I've created an open source project, called GitHubFolderDownloader. It lets you to download a single folder of a repository without cloning or downloading the whole repository.
VahidNVahidN
Nothing wrong with other answers but I just thought I'd share step-by-step instructions for those wandering through this process for the first time.
How to download a single folder from a github repository (Mac OS X):
~ To open Terminal just click spotlight and type terminal then hit enter
- On a Mac you likely already have SVN (to test just open terminal andtype 'svn' or 'which svn' ~ without the quote marks)
- On Github: Locate the Github path to your git folder (not the repo) by clicking the specific folder name within a repo
- Copy the path from the address bar of the browser
- Open Terminal and type: svn export
- Next paste in the address (eg.):https://github.com/mingsai/Sample-Code/tree/master/HeadsUpUI
- Replace the words: tree/master
- with the word: trunk
- Type in the destination folder for the files (in this example, Istore the target folder inside of the Downloads folder for thecurrent user)
- Here space is just the spacebar not the word (space) ~/Downloads/HeadsUpUI
- The final terminal command shows the full command to download the folder (compare the address to step 5) svn export https://github.com/mingsai/Sample-Code/trunk/HeadsUpUI ~/Downloads/HeadsUpUI
BTW - If you are on Windows or some other platform you can find a binary download of subversion (svn) at http://subversion.apache.org
~ If you want to checkout the folder rather than simply download it try using the svn help (tldr: replace export with checkout)
Update
Regarding the comment on resuming an interrupted download/checkout. I would try running
svn cleanup
followed by svn update
. Please search SO for additional options.Tommie C.Tommie C.
Whoever is working on specific folder he needs to clone that particular folder itself, to do so please follow below steps by using sparse checkout.
- Create a directory.
- Initialize a Git repository. (
git init
) - Enable Sparse Checkouts. (
git config core.sparsecheckout true
) - Tell Git which directories you want (echo 2015/brand/May( refer to folder you want to work on) >>
.git/info/sparse-checkout
) - Add the remote (
git remote add -f origin https://jafartke.com/mkt-imdev/DVM.git
) - Fetch the files (
git pull origin master
)
Mohammed JafarMohammed Jafar
You cannot; unlike Subversion, where each subdirectory can be checked out individually, Git operates on a whole-repository basis.
For projects where finer-grained access is necessary, you can use submodules -- each submodule is a separate Git project, and thus can be cloned individually.
It is conceivable that a Git front-end (e.g. GitHub's web interface, or gitweb) could choose to provide an interface for you to extract a given folder, but to my knowledge none of them do that (though they do let you download individual files, so if the folder does not contain too many files, that is an option)
Edit - GitHub actually offers access via SVN, which would allow you to do just this (as per comment). See https://github.com/blog/1438-improved-svn-here-to-stay-old-svn-going-away for latest instructions on how to do this
michel-slmmichel-slm
If you truly just want to just 'download' the folder and not 'clone' it (for development), the easiest way to simply get a copy of the most recent version of the repository (and therefore a folder/file within it), without needing to clone the whole repo or even install git in the first place, is to download a zip archive (for any repo, fork, branch, commit, etc.) by going to the desired repository/fork/branch/commit on GitHub (e.g.
http(s)://github.com/<user>/<repo>/commit/<Sha1>
for a copy of the files as they were after a specific commit) and selecting the Downloads
button near the upper-right.This archive format contains none of the git-repo magic, just the tracked files themselves (and perhaps a few .gitignore files if they were tracked, but you can ignore those :p) - that means that if the code changes and you want to stay on top, you'll have to manually re-download it, and it also means you won't be able to use it as a git repository...
Not sure if that's what you're looking for in this case (again, 'download'/view vs 'clone'/develop), but it can be useful nonetheless...
johnnyjohnny
1.Click on this link http://kinolien.github.io/gitzip/
2.Paste link of Github folder you want to download.
3.Click on search it will shows all files for downloading.
Note:-Using search there is no need to enter token key ;)..keep it simple(y)
2.Paste link of Github folder you want to download.
3.Click on search it will shows all files for downloading.
Note:-Using search there is no need to enter token key ;)..keep it simple(y)
Muhammad YounusMuhammad Younus
Another specific example:
Like I want to download 'iOS Pro Geo' folder from the url
https://github.com/alokc83/APRESS-Books-Source-Code-/tree/master/%20Pro%20iOS%20Geo
and I can do so via
Note trunk in the path
Edited: (as per Tommie C's comment)
Yes, using export instead of checkout would give a clean copy without extra git repository files.
Edited: If tree/master is not there in url then Fork it and it will be there in Forked url.
zeeawanzeeawan
It's one of the few places where SVN is better than Git.
In the end we've gravitated towards three options:
- Use wget to grab the data from GitHub (using the raw file view).
- Have upstream projects publish the required data subset as build artifacts.
- Give up and use the full checkout. It's big hit on the first build, but unless you get lot of traffic, it's not too much hassle in the following builds.
Manish ShrivastavaManish Shrivastava
If you are comfortable with unix commands, you don't need special dependencies or web apps for this. You can download the repo as a tarball and untar only what you need.
Example (woff2 files from a subdirectory in fontawesome):
- More about the link format: https://developer.github.com/v3/repos/contents/#get-archive-link (including how to get a zip file or specific branches/refs)
- Keep the initial part of the path (
*/
) to match any directory. Github creates a wrapper directory with the commit ref in the name, so it can't be known. - You probably want
--strip-components
to be the same as the amount of slashes (/
) in the path (previous argument).
This will download the whole tarball. Use the SVN method mentioned in the other answers if this has to be avoided or if you want to be nice to the GitHub servers.
AlbinAlbin
There's a Python3 pip package called
githubdl
that can do this*:The project page is here
* Disclaimer: I wrote this package.
Willem van KetwichWillem van Ketwich
You can do a simple download of the directory tree:
But if you mean to check it out, and be able to do commits and push them back, no you can't do that.
araqnidaraqnid
Just to amplify the answers above, a real example from a real GitHub repository to a local directory would be:
Sometimes a concrete example helps clarify the substitutions proposed.
John WashburnJohn Washburn
I use linux so , put this in ~/.bashrc , called even :D $HOME/.bashrc
then refresh the shell with
then use it with git-downloadfolder blablabla :D
user1088530user1088530
Our team wrote a bash script to do this because we didn't want to have to install SVN on our bare bones server.
It uses the github API and can be run from the command line like this:
Yogesh ChawlaYogesh Chawla
I work with CentOS 7 servers on which I don't have root access, nor git, svn, etc (nor want to!) so made a python script to download any github folder: https://github.com/andrrrl/github-folder-downloader
Usage is simple, just copy the relevant part from a github project, let's say the project is https://github.com/MaxCDN/php-maxcdn/, and you want a folder where some source files are only, then you need to do something like:
$ python gdownload.py '/MaxCDN/php-maxcdn/tree/master/src' /my/target/dir/
(will create target folder if doesn't exist)
It requires lxml library, can be installed with
If you don't have root access (like me) you can create a
easy_install lxml
If you don't have root access (like me) you can create a
.pydistutils.py
file into your $HOME
dir with these contents:[install]user=1
And easy_install lxml
will just work (ref: https://stackoverflow.com/a/33464597/591257).Community♦
aesedeaesede
None of the answers helped in my situation. If you are developing for Windows, you likely don't have svn. In many situations one can't count on users to have Git installed either, or don't want to download entire repositories for other reasons. Some of the people that answered this question, such as Willem van Ketwich and aztack, made tools to accomplish this task. However, if the tool isn't written for the language you are using, or you don't want to install a third party library, these don't work.
However, there is a much easier way. GitHub has an API that allows you to download a single file or an entire directory's contents using GET requests. You can access a directory using
https://api.github.com/repos/:owner/:repo_name/contents/:path
that returns a JSON object enumerating all the files in the directory. Included in the enumeration is a link to the raw content of the file, the download_url
parameter. The file can then be downloaded using that URL.It's a two step process that requires the ability to make GET requests, but this can be implemented in pretty much any language, on any platform. It can be used to get files or directories.
CalvinCalvin
To export a directory from GitHub, replace '/tree/master/' in the directory's url with '/trunk/'.
For example, to export the directory from the following URL:
run the following command:
Martijn Pieters♦
Mohsen AbasiMohsen Abasi
If you need to do it programatically and you don't want to rely on SVN, you can use GitHub API to download all the contents recursively.
For inspiration, here's my ruby gist: https://gist.github.com/cvengros/b2a7e82f66519d423b6f
pcvpcv
I wrote a tool with Node.js just for this. Check it out Download Repo Dir
install with
npm i -g dl-repo-dir
and command repo
will be available globally.repo download aztack/download-repo-dir lib src/lib/new-name
repo download aztack/download-repo-dir ' src/lib/download-repo-dir
export GITLAB_API_PRIVATE_TOKEN=YOUR_TOKEN_HERE
repo download gitlab:mygitlab.com:topgroup/subgroup/repo#v1.0.0 dir src/lib/new-name
and there will be a
repo.json
file to save all the information.In a new project, you can initialize the project with exists
repo.json
using repo init
command.aztackaztack
Use this function, the first argument is the url to the folder, the second is the place the folder will be downloaded to:
HappyFaceHappyFace
If you want to use Python and SVN to download a specific GitHub directory, here is the code that you would use:
You can check more details about this code and other GitHub search and download tips in this tutorial: https://python.gotrained.com/search-github-api/
GoTrainedGoTrained
A straightforward answer to this is to first tortoise svn from following link.
while installation turn on CLI option, so that it can be used from command line interface.
copy the git hub sub directory link.
Example
replace tree/master with trunk
and do
svn checkout https://github.com/tensorflow/models/trunk/research/deeplab
files will be downloaded to the deeplab folder in the current directory.
KhanKhan
If the directoy you want to download is a separated library, it's better to create an other git repo, and then to use the git submodule function.
Of course, you have to be the owner of the initial repo you want
AsenarAsenar
protected by jtbandesAug 18 '16 at 5:56
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?