microgit-cli

中文文档
0.1.1发布于 2026/11/04MITES Module零依赖

Command line client for a self-hosted git server (microgit)

原始使用文档
文档目录14 节
  1. Install
  2. Interactive shell
  3. Quick start
  4. Commands
  5. Creating repositories
  6. Starting a local repository
  7. Deleting repositories
  8. Listing repositories
  9. Authentication and git credentials
  10. Config file
  11. Renaming the CLI
  12. Domains
  13. Exit codes
  14. Troubleshooting

microgit-cli

microgit — your own git server — clone, push, host.

A small command line client for the microgit server. It keeps the API session in a local config file, creates and deletes repositories, and wraps the usual git commands so push/pull work with the account credentials.

It is a separate TypeScript project with no runtime dependencies (Node's built-in fetch, readline and git are enough).

Install

npm install -g microgit-cli

Without a global install, run the built entry point directly:

node src/index.js --help

Interactive shell

Run microgit with no arguments (or microgit shell) to open the shell:

  ● ━━━ ●
    ┣━━━ ●   microgit-cli • gitserver  v0.1.0
    ┗━━━ ●   your own git server — clone, push, host

  # server   http://{HOST_NAME}:{PORT}
  # account  alice · 7d left

  ✓ ready · type help to list the commands
  # one-shot microgit --help

alice@microgit:~/repos$ new app

Starting the shell clears the screen and the scrollback first, so the banner is the only thing on the page. The prompt shows the signed-in account and the current folder. Commands are the same words as the one-shot CLI, and the shell adds:

Keys / commandWhat it does
↑ / ↓History, kept in ~/.microgit/history
TabComplete command names, config actions and --options
Ctrl+CClear the line; on an empty line it leaves the shell
Ctrl+DLeave the shell
helpThe command list
clearClear the screen and redraw the banner
exit / quitLeave the shell

Errors never close the shell. A command that asks something (login, commit, delete, new) asks inside the same prompt.

Quick start

# 1. Point the CLI at the server and sign in. Use the host and port the
#    server actually listens on, or its domain behind a reverse proxy.
microgit login --url http://{HOST_NAME}:{PORT}

# 2. Create a repository and a local checkout with a first commit,
#    then push it.
microgit new app --init

# 3. Work as usual; commit also pushes.
cd app
echo "hello" > hello.txt
microgit commit -m "Add hello.txt"

# 4. Check the session or list repositories.
microgit whoami
microgit list

Signing in again reuses a valid stored session, so the username and password are only asked for once. Add --force to sign in as another account.

Commands

CommandWhat it does
microgit loginSign in, store the API token and optionally the git password
microgit registerCreate an account (when the server allows registration) and sign in
microgit logoutRevoke the server session, remove the local token and password
microgit whoamiShow the signed-in account, server and expiry
microgit new <name>Create a repository; asks public/private, plus --private, --public, --clone, --init
microgit listList repositories; --owner, --name, --public, --private
microgit delete <name|owner/name>Delete a repository; asks before doing it
microgit clone <name|owner/name> [dir]Clone using the clone URL from the server
microgit init [dir]Local only: project folder, git init and an empty README.md
microgit statusgit status --short --branch
microgit commit -m "message"git add -A, commit, then push
microgit push [git args]Push with stored credentials
microgit pull [git args]Pull with stored credentials
microgit configShow the config file, server and session

Every command accepts -h / --help. Commands that print API data also accept --json where it makes sense (whoami, list, new, delete, clone, login, register, logout, config).

Creating repositories

Without --private or --public the CLI asks for the visibility, and Enter creates a public repository:

microgit new app                  # asks: public or private
microgit new secret --private
microgit new app --public
microgit new app --clone          # create it and clone the empty repository
microgit new app --init           # create it, README, first commit and push
microgit new app --init --dir ./projects/app

The request sent to the server is {"name":"app","private":false} (or true).

new prints the server's clone URL. Existing repositories are not an error: the API returns created: false and the CLI says it already exists.

Starting a local repository

microgit init is local only — it does not talk to the server:

microgit init app        # creates ./app, .git on main, empty README.md
microgit init            # initialise the current folder
microgit init --dir ./projects/app

It refuses to run inside an existing repository, and reuses the saved account name for user.name / user.email when git has none configured.

Deleting repositories

microgit delete app                 # asks for confirmation
microgit delete app --yes           # non-interactive
microgit delete bob/app --yes       # administrators can delete for another owner

Listing repositories

microgit list
microgit list --owner alice
microgit list --private --limit 20
microgit list --public --page 2 --json

Authentication and git credentials

The JSON API uses the session token returned by login. The CLI sends it as Authorization: Bearer <token> and stores it in the config file. Git uses HTTP Basic with the account username and password, not the API token.

For that reason login only stores the token by default. Add --save-password to also store the password, which makes push, pull, clone of a private repository and new --init work without another prompt:

microgit login --save-password

The password is stored in plain text in the config file. The file is created with mode 600 on Unix; on Windows the user profile permissions apply. If you do not want to store it, leave --save-password off and let git ask when it needs credentials, or set MICROGIT_PASSWORD for one command:

MICROGIT_PASSWORD='alicepass1' microgit push

Logging in again keeps a saved password when the username is unchanged; pass --forget-password to remove it.

The CLI passes credentials to git as an http.extraHeader, so they are not written into .git/config and are not part of the clone URL.

The server's message of the day, when it publishes one, is printed after login, register and whoami.

Config file

Default location: ~/.microgit/config.json. Use MICROGIT_CONFIG to point at a different file, for example one per server:

MICROGIT_CONFIG=~/.microgit/work.json microgit login --url https://git.example.com

The shell keeps its history next to it, in ~/.microgit/history.

Show it with:

microgit config
microgit config set url https://git.example.com
microgit config set username alice
microgit config unset password
microgit config clear

Environment variables override the file for one command:

VariableMeaning
MICROGIT_URLServer URL
MICROGIT_TOKENAPI token, instead of the stored one
MICROGIT_USERNAMEAccount name, also used for git
MICROGIT_PASSWORDGit password, also used for git
MICROGIT_CONFIGConfig file path
NO_COLORDisable colours

Renaming the CLI

Package name, command name, banner, tagline, label, version, environment prefix and config folder all live in src/settings.ts. Change them there and update name / bin in package.json to match.

Domains

The server's domain / publicUrl setting changes the clone URL it returns. microgit clone and microgit new --init use that URL, so the name must resolve from the machine running the CLI. If the public domain is only reachable from outside, log in with the internal URL instead; the repository still works, but a domain configured on the server wins when it builds the clone URL.

Exit codes

  • 0 success
  • 1 expected failure (bad input, server error, git failure)

Errors are printed once without a stack trace. --json output is still the server's JSON (or, for whoami/config, a small object with the same fields).

Troubleshooting

  • You are not signed in — run microgit login; the token expires after the server's sessionDays.
  • login keeps signing in as the old account — the stored session is still valid; pass --force or run microgit logout first.
  • Authentication failed on push — login --save-password, or set MICROGIT_PASSWORD; the username/password is your account, not the API token.
  • No 'origin' remote — use microgit clone <owner/name> or add a remote with git.
  • Directory is not empty — --clone/--init refuse to overwrite files; choose another --dir.
  • Already a git repository — microgit init skips folders that already have .git.
  • Server unreachable — pass --url or set MICROGIT_URL; check the server's host, port and reverse proxy.

版本与发布记录

microgit-cli 共发布 2 个版本,首次发布于 2026/11/04;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.1.1latest2026/11/04今天
0.0.0-stage2026/11/04今天

关于 microgit-cli 的常见问题

microgit-cli 是什么?

Command line client for a self-hosted git server (microgit)

如何安装 microgit-cli?

在项目目录运行 npm install microgit-cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 microgit,可以用 npx microgit 直接运行。

microgit-cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/microgit-cli 是否存在。

microgit-cli 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

microgit-cli 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

microgit-cli 可以商用吗?

microgit-cli 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

microgit-cli 还在维护吗?

最新版本 0.1.1 发布于 2026/11/04(今天);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/11/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。