Straightforward project scaffolding tool that clones git repositories without history
npx @tessl/cli install tessl/npm-degit@2.8.0degit is a straightforward project scaffolding tool that creates copies of git repositories without the entire git history. It downloads tar files of the latest commits from GitHub, GitLab, BitBucket, and Sourcehut, providing faster cloning than traditional git clone. The tool supports branch/tag/commit specification, subdirectory cloning, private repository access via git mode, HTTPS proxy support, and offline caching.
npm install -g degit (CLI) or npm install degit (API)import degit from "degit";For CommonJS:
const degit = require("degit");# Clone a repository
degit user/repo my-project
# Clone specific branch/tag
degit user/repo#dev my-project
degit user/repo#v1.2.3 my-project
# Clone with options
degit user/repo my-project --force --verboseimport degit from "degit";
// Create degit instance
const emitter = degit("user/repo", {
cache: false,
force: true,
verbose: true
});
// Handle events
emitter.on("info", info => console.log(info.message));
emitter.on("warn", warn => console.warn(warn.message));
// Clone repository
await emitter.clone("./my-project");degit is built around several key components:
degit() creates and returns a new Degit instanceCore repository cloning functionality supporting multiple git platforms and cloning modes.
function degit(src: string, opts?: DegitOptions): DegitInstance;
interface DegitOptions {
cache?: boolean;
force?: boolean;
verbose?: boolean;
mode?: "tar" | "git";
}Post-clone manipulation system allowing repositories to define automated actions via degit.json configuration files.
interface DegitAction {
action: "clone" | "remove";
}
interface CloneAction extends DegitAction {
action: "clone";
src: string;
cache?: boolean;
verbose?: boolean;
}
interface RemoveAction extends DegitAction {
action: "remove";
files: string | string[];
}Full-featured CLI for interactive and scripted repository cloning with support for various options and interactive mode.
degit <src>[#ref] [<dest>] [options]
Options:
--help, -h Show help message
--cache, -c Only use local cache
--force, -f Allow non-empty destination directory
--verbose, -v Extra logging
--mode=, -m= Force the mode by which degit clones the repo (tar or git)user/repo # GitHub (default)
github:user/repo # GitHub explicit
gitlab:user/repo # GitLab
bitbucket:user/repo # BitBucket
git.sr.ht/user/repo # Sourcehut
https://github.com/user/repo # HTTPS URL
git@github.com:user/repo # SSH URLuser/repo # Latest commit (HEAD)
user/repo#branch-name # Specific branch
user/repo#v1.2.3 # Specific tag
user/repo#abcd1234 # Specific commit hash
user/repo/subdirectory # Subdirectory only// Degit class is not directly exported, only accessible via degit() factory function
interface DegitInstance extends EventEmitter {
clone(dest: string): Promise<void>;
remove(dir: string, dest: string, action: RemoveAction): void;
// Properties
src: string;
cache: boolean;
force: boolean;
verbose: boolean;
proxy?: string;
repo: RepoInfo;
mode: "tar" | "git";
directiveActions: DirectiveActions;
}
interface DegitOptions {
cache?: boolean;
force?: boolean;
verbose?: boolean;
mode?: "tar" | "git";
}
// Actions system types
interface DegitAction {
action: "clone" | "remove";
}
interface CloneAction extends DegitAction {
action: "clone";
src: string;
cache?: boolean;
verbose?: boolean;
}
interface RemoveAction extends DegitAction {
action: "remove";
files: string | string[];
}
interface DirectiveActions {
clone: (dir: string, dest: string, action: CloneAction) => Promise<void>;
remove: (dir: string, dest: string, action: RemoveAction) => void;
}
// Event types
interface InfoEvent {
code: string;
message: string;
repo?: RepoInfo;
dest?: string;
}
interface WarnEvent {
code: string;
message: string;
}
// Error types
class DegitError extends Error {
constructor(message: string, opts: ErrorOptions);
}
interface ErrorOptions {
code: string;
[key: string]: any;
}
// Repository info
interface RepoInfo {
site: string;
user: string;
name: string;
ref: string;
url: string;
ssh: string;
subdir?: string;
mode: "tar" | "git";
}