or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

actions.mdcli.mdcloning.mdindex.md
tile.json

tessl/npm-degit

Straightforward project scaffolding tool that clones git repositories without history

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/degit@2.8.x

To install, run

npx @tessl/cli install tessl/npm-degit@2.8.0

index.mddocs/

degit

degit 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.

Package Information

  • Package Name: degit
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install -g degit (CLI) or npm install degit (API)

Core Imports

import degit from "degit";

For CommonJS:

const degit = require("degit");

Basic Usage

CLI Usage

# 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 --verbose

API Usage

import 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");

Architecture

degit is built around several key components:

  • Factory Function: degit() creates and returns a new Degit instance
  • Degit Class: Main class extending EventEmitter for repository operations
  • Repository Parser: Handles different repository URL formats and platforms
  • Download Modes: Supports both tar archive (default) and git clone modes
  • Cache Management: Local caching system for downloaded archives
  • Action System: Support for post-clone operations via degit.json files

Capabilities

Repository Cloning

Core 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";
}

Repository Cloning

Actions System

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[];
}

Actions System

Command Line Interface

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)

Command Line Interface

Supported Platforms

Git Hosting Services

  • GitHub: github.com (default platform)
  • GitLab: gitlab.com
  • BitBucket: bitbucket.org
  • Sourcehut: git.sr.ht

Repository URL Formats

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 URL

Reference Specifications

user/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

Types

// 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";
}