名称: gitload
描述: >
当用户要求“从 GitHub 下载文件”、“从仓库获取文件夹”、“从 GitHub 获取代码”、“下载 GitHub 仓库”、“从 GitHub URL 获取文件”、“仅克隆文件夹”,或需要在不克隆整个仓库的情况下下载 GitHub 上的特定文件/文件夹时,应使用此技能。
使用 gitload CLI 从 GitHub URL 下载文件、文件夹或整个仓库。
在以下情况下使用 gitload:
- 从仓库下载特定文件夹(而非整个仓库)
- 从 GitHub 获取单个文件
- 下载仓库内容(不含 git 历史记录)
- 创建 GitHub 内容的 ZIP 归档
- 通过身份验证访问私有仓库
不要在以下情况下使用 gitload:
- 需要完整的 git 历史记录(请改用 git clone)
- 仓库已克隆到本地
- 处理非 GitHub 仓库
通过 npx 运行 gitload(无需安装):
npx gitload-cli https://github.com/user/repo
或全局安装:
npm install -g gitload-cli
gitload https://github.com/user/repo
在当前目录创建 repo/ 文件夹。
gitload https://github.com/user/repo/tree/main/src/components
仅下载该文件夹内容,并创建 components/ 文件夹。
gitload https://github.com/user/repo/blob/main/README.md
gitload https://github.com/user/repo/tree/main/src -o ./my-source
gitload https://github.com/user/repo/tree/main/templates -o .
gitload https://github.com/user/repo -z ./repo.zip
gitload https://github.com/user/private-repo --gh
需要先运行 gh auth login。
gitload https://github.com/user/repo --token ghp_xxxx
export GITHUB_TOKEN=ghp_xxxx
gitload https://github.com/user/repo
令牌优先级: --token > GITHUB_TOKEN > --gh
gitload 接受标准 GitHub URL:
- 仓库根目录: https://github.com/user/repo
- 文件夹: https://github.com/user/repo/tree/branch/path/to/folder
- 文件: https://github.com/user/repo/blob/branch/path/to/file.ext
gitload https://github.com/org/templates/tree/main/react-starter -o ./my-app
cd my-app && npm install
gitload https://github.com/org/examples/tree/main/authentication
gitload https://github.com/org/project/tree/main/docs -z ./docs.zip
gitload https://github.com/org/configs/blob/main/.eslintrc.json -o .
| 选项 | 描述 |
|---|---|
-o, --output <dir> |
输出目录(默认:基于 URL 路径命名的文件夹) |
-z, --zip <path> |
将内容保存为指定路径的 ZIP 文件 |
-t, --token <token> |
GitHub 个人访问令牌 |
--gh |
使用 gh CLI 中的令牌 |
--no-color |
禁用彩色输出 |
-h, --help |
显示帮助信息 |
-V, --version |
输出版本信息 |
如果 gitload 失败:
1. 404 错误: 确认 URL 存在且可访问
2. 速率限制错误: 使用 --gh 或 --token 添加身份验证
3. 权限错误: 对于私有仓库,确保令牌具有 repo 权限范围
4. 网络错误: 检查网络连接
git clone)