Package Exports
- giget
Readme
✨ giget
Easily download git repositories
Features
✔ Multi-provider support (GitHub, GitLab, and bitbucket)
✔ Super fast cloning using tarball gzip without depending on local git
or tar
commands.
✔ Works online and offline with fallback
✔ Support extracting with a subpath
Usage (CLI)
npx giget@latest <repo> [<dir>]
Arguments
- repo: A URI describing provider, repository, subpath, and branch/ref. (format is
[provider]:user/name[/path][#ref]
.) - dir: A relative or absolute path where to extract the repository. (if not provided, the name of the repo will be used as the directory name in the current working directory.)
Examples
# Clone the main branch of github.com/unjs/template to unjs-template directory
npx giget@latest unjs/template
# Clone to myProject directory
npx giget@latest unjs/template myProject
# Clone dev branch
npx giget@latest unjs/template#dev
# Clone /test directory from main branch
npx giget@latest unjs/template/test
# Clone from gitlab
npx giget@latest gitlab:unjs/template
# Clone from bitbucket
npx giget@latest butbucket:unjs/template
Usage (Programmatic)
Install package:
# npm
npm install giget
# yarn
yarn install giget
# pnpm
pnpm install giget
Import:
// ESM
import { downloadRepo } from 'giget'
// CommonJS
const { downloadRepo } = require('giget')
downloadRepo(source, dir, options?)
Example:
const { source, dir } = await downloadRepo('github:unjs/template')
Parameters:
source
: (string) Input source in format of[provider]:user/name[/path][#ref]
.dst
: (string) Destination directory to clone to. If not provided,user-name
will be used relative to the current directory.options
: (object) Options are usually inferred from the input string. You can customize them.provider
: (string) Eithergithub
,gitlab
orbitbucket
. The default isgithub
.repo
: (string) Name of repository in format of{username}/{reponame}
.ref
: (string) Git ref (branch or commit or tag). The default value ismain
.subpathpath
: (string) subpath of the repo to clone from. The default value is none.
Return value:
The return value is a promise that resolves to an object with the following properties:
dir
: (string) Path to extracted dir.source
: (string) Normalized version of the input source. Useful for logging.
💻 Development
- Clone this repository
- Enable Corepack using
corepack enable
(usenpm i -g corepack
for Node.js < 16.10) - Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
Related projects
- https://github.com/samsonjs/gitter
- https://github.com/tiged/tiged
- https://github.com/Rich-Harris/degit
License
Made with 💛
Published under MIT License.