如何从 github 下载文件夹?

How to download a folder from github?

我想从此 link 下载 mysite 文件夹: https://github.com/username/repository/master/

有一个按钮 Download ZIP。如果您想进行稀疏结账,网站上有很多解决方案。例如here.

可以 从github

下载file/folder

只需使用:svn export <repo>/trunk/<folder>

例如:svn export https://github.com/lodash/lodash/trunk/docs

注意:您可以先在终端使用svn ls <repo>/trunk/folder

列出文件夹的内容

(是的,这里是 svn。显然在 2016 年你仍然需要 svn 来简单地下载一些 github 文件)

您可以使用 Github Contents API 获取存档 link 并使用 tar 检索指定文件夹。

命令行:

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


例如,
如果你想下载examples/with-apollo/ folder from zeit/next.js,你可以输入:

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

您也可以只克隆repo,克隆完成后,只需选择您想要的文件夹或vile。要克隆:

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

然后转到克隆的目录并找到您要复制的文件或目录。

您可以在克隆或下载选项下下载完整文件夹(Git URL 或下载 Zip)

  1. 有一个下载 Zip 的按钮

  2. 通过使用命令,您可以在您的计算机上下载完整的文件夹,但为此您需要在您的计算机上安装 git。您可以找到 Git url uner

    git 克隆 https://github.com/url

使用GitZip online tool。它允许将 sub-directory 的 git 集线器存储库下载为 zip 文件。不需要 git 个命令!

依赖关系:cURL and 7-Zip.

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

例如:

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

如何从 GitHub 存储库下载特定文件夹

这里是根据这个 post:

的正确解决方案
  • 创建目录

     mkdir github-project-name 
     cd github-project-name
    
  • 设置 git 存储库

     git init
     git remote add origin <URL-link of the repo>
    
  • 配置您的 git-repo 以仅下载特定目录

     git config core.sparseCheckout true # enable this
    
  • 设置您要下载的文件夹,例如您只想从 https://github.com/project-tree/master/doc

    下载 doc 目录
     echo "/absolute/path/to/folder" > .git/info/sparse-checkout 
    

    例如如果您只想从主存储库 https://github.com/project-tree/master/doc 下载 doc 目录,那么您的命令是 echo "doc" > .git/info/sparse-checkout.

  • 照常下载您的存储库

     git pull origin master
    

如果您想自动执行这些步骤,此处的建议只能在一定程度上起作用。

我遇到了这个名为 fetch 的工具,它对我来说效果很好。您甚至可以指定版本。因此,需要一个步骤来下载并将其设置为可执行文件,然后获取所需的文件夹:

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

还有一个不错的浏览器扩展,允许 dl 文件或文件夹