npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@git-lazy/subtree

v2.0.3

Published

Programmatic wrapper for git subtree operations including add, push, pull, and split

Downloads

428

Readme

@git-lazy/subtree

Programmatic wrapper for git subtree operations including add, push, pull, and split

Installation

npm install @git-lazy/subtree
# or
pnpm add @git-lazy/subtree
# or
yarn add @git-lazy/subtree

Usage

import { subtreeAdd, subtreePush, subtreePull, subtreeSplit } from '@git-lazy/subtree';

// 新增 subtree / Add subtree
await subtreeAdd({
  prefix: 'packages/my-lib',
  remote: 'https://github.com/user/my-lib.git',
  branch: 'main',
});

// 推送 subtree / Push subtree
await subtreePush({
  prefix: 'packages/my-lib',
  remote: 'origin',
  branch: 'main',
});

// 拉取 subtree / Pull subtree
await subtreePull({
  prefix: 'packages/my-lib',
  remote: 'origin',
  branch: 'main',
});

// 分割 subtree / Split subtree
await subtreeSplit({
  prefix: 'packages/my-lib',
  branch: 'extracted-branch',
});

CLI

# 使用 CLI 工具 / Use CLI tool
npx subtree add --prefix packages/my-lib --remote origin --branch main
npx subtree push --prefix packages/my-lib --remote origin --branch main
npx subtree pull --prefix packages/my-lib --remote origin --branch main
npx subtree split --prefix packages/my-lib --branch extracted

API

subtreeAdd(options)

新增 git subtree / Add a git subtree

將遠端倉庫的指定分支合併到本地專案的指定前綴路徑 / Merges a specified branch from a remote repository into the local project at the specified prefix path

Parameters:

  • options (IOptionsCommon) - 通用選項設定 / Common options configuration
    • prefix (string) - 子樹目錄路徑 / Subtree directory path
    • remote (string) - 遠端倉庫名稱或 URL / Remote repository name or URL
    • branch (string, optional) - 分支名稱,預設為 'master' / Branch name, defaults to 'master'
    • squash (boolean, optional) - 是否合併提交記錄 / Whether to squash commit history
    • cwd (string, optional) - 工作目錄 / Working directory

Returns: Promise - Git 命令執行結果 / Git command execution result

Example:

await subtreeAdd({
  prefix: 'packages/my-lib',
  remote: 'https://github.com/user/my-lib.git',
  branch: 'main',
  squash: true,
});

subtreePush(options)

推送 git subtree 到遠端倉庫 / Push a git subtree to a remote repository

將本地指定前綴路徑的變更推送到遠端倉庫的指定分支 / Pushes changes from the local specified prefix path to the specified branch of the remote repository

Parameters:

  • options (IOptionsCommon) - 通用選項設定 / Common options configuration
    • prefix (string) - 子樹目錄路徑 / Subtree directory path
    • remote (string) - 遠端倉庫名稱或 URL / Remote repository name or URL
    • branch (string, optional) - 分支名稱,預設為 'master' / Branch name, defaults to 'master'
    • squash (boolean, optional) - 是否合併提交記錄 / Whether to squash commit history
    • cwd (string, optional) - 工作目錄 / Working directory

Returns: Promise - Git 命令執行結果 / Git command execution result

Example:

await subtreePush({
  prefix: 'packages/my-lib',
  remote: 'origin',
  branch: 'main',
});

subtreePull(options)

從遠端倉庫拉取 git subtree 更新 / Pull git subtree updates from a remote repository

從遠端倉庫的指定分支拉取變更並合併到本地指定前綴路徑 / Pulls changes from the specified branch of the remote repository and merges them into the local specified prefix path

Parameters:

  • options (IOptionsCommon) - 通用選項設定 / Common options configuration
    • prefix (string) - 子樹目錄路徑 / Subtree directory path
    • remote (string) - 遠端倉庫名稱或 URL / Remote repository name or URL
    • branch (string, optional) - 分支名稱,預設為 'master' / Branch name, defaults to 'master'
    • squash (boolean, optional) - 是否合併提交記錄 / Whether to squash commit history
    • cwd (string, optional) - 工作目錄 / Working directory

Returns: Promise - Git 命令執行結果 / Git command execution result

Example:

await subtreePull({
  prefix: 'packages/my-lib',
  remote: 'origin',
  branch: 'main',
  squash: true,
});

subtreeSplit(options)

分割 git subtree 為獨立分支 / Split a git subtree into a separate branch

將指定前綴路徑的歷史記錄提取為獨立分支,可用於建立子模組或獨立倉庫 / Extracts the history of the specified prefix path into a separate branch, useful for creating submodules or standalone repositories

Parameters:

  • options (IOptionsSplit) - 分割選項設定 / Split options configuration
    • prefix (string) - 子樹目錄路徑 / Subtree directory path
    • branch (string) - 分支名稱 / Branch name
    • rejoin (boolean, optional) - 是否重新加入已分割的提交 / Whether to rejoin split commits
    • ignoreJoins (boolean, optional) - 是否忽略之前的 join 記錄 / Whether to ignore previous join records
    • cwd (string, optional) - 工作目錄 / Working directory

Returns: Promise - Git 命令執行結果 / Git command execution result

Example:

// 基本分割 / Basic split
await subtreeSplit({
  prefix: 'packages/my-lib',
  branch: 'extracted-branch',
});

// 使用 rejoin 選項繼續累積提交 / Use rejoin option to continue accumulating commits
await subtreeSplit({
  prefix: 'packages/my-lib',
  branch: 'extracted-branch',
  rejoin: true,
});

Types

IOptionsCommon

通用選項型別,用於 add/push/pull 操作 / Common options type for add/push/pull operations

IOptionsSplit

Split 選項型別,用於 git subtree split 操作 / Split options type for git subtree split operations

EnumSubtreeCmd

Subtree 命令列舉:add | push | pull | split / Subtree command enumeration

EnumPrefixType

Prefix 類型列舉:ROOT | RELATIVE | ABSOLUTE / Prefix type enumeration

License

ISC