Skip to content

Clone git repositories with ease from Javascript

License

Notifications You must be signed in to change notification settings

Tommypop2/begit

Repository files navigation

Begit

A smaller and lighter degit alternative with Typescript support.

Features

  • Fast
    • Caches results by default so nothing is refetched unnecessarily
  • Small
    • Only 13.1kB unpacked on npm (actual source code is more like 1.4kB minified)
  • Fault-tolerant
    • Can recover from a corrupted cache file
  • XDG Friendly
  • Minimal Dependencies
    • Only has a single dependency (tar) for extracting the downloaded tarballs

Begit CLI

A small CLI wrapper for @begit/core

Installation

Run npm i -g @begit/cli to install. Invoke with begit

Usage

For a comprehensive list of features, use the help command as below:

begit --help

Which will print something like:

begit

ARGUMENTS:
  <URL>         - The URL to clone
  [Destination] - a string [optional]

OPTIONS:
  --subdir, -s <str> - a string [optional]

FLAGS:
  --help, -h - show help

Cloning a repositoy

To clone a repository to the current working directory, simply:

begit Tommypop2/begit

URLs are also accepted:

begit https://github.com/Tommypop2/begit

You can also specify the desired branch via a #:

begit Tommypop2/begit#main

Cloning a subdirectory within a repo

Use any of the above options in conjunction with the --subdir flag.

begit Tommypop2/begit --subdir packages

Or, shortened to -s

begit Tommypop2/begit -s packages

API Reference

Cloning to a directory

import { downloadRepo } from "@begit/core";
await downloadRepo({
 repo: {
  owner: "Tommypop2",
  name: "begit",
  branch: undefined,
  subdir: undefined,
 },
 "cool_project",
});

The code above downloads this repository into a folder named cool_project.

Alternatively, downloadAndExtract could be used in place of downloadRepo to opt out of automatically attempting to handle errors

Providing a custom commit hash

import { downloadRepo } from "@begit/core";

const custom_hash = "9e4e51beb1ac76e6c37be1757f14b904617a2f9b";

await downloadRepo({
 repo: {
  owner: "Tommypop2",
  name: "begit",
  branch: undefined,
  subdir: undefined,
  hash: custom_hash,
 },
 "cool_project",
});

Fetching the most recent cached commit

import { downloadRepo } from "@begit/core";

const most_recent_hash = await getMostRecentCachedCommit("Tommypop2", "begit"); // string | undefined

await downloadRepo({
 repo: {
  owner: "Tommypop2",
  name: "begit",
  branch: undefined,
  subdir: undefined,
  hash: most_recent_hash,
 },
 "cool_project",
});

About

Clone git repositories with ease from Javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published