xgit-utils
用于克隆和同步 Git 镜像仓库,以及列出或导出 GitHub 仓库的命令行工具。
环境要求
- Python 3.10 或更高版本
- 已安装 Git,且 Git 命令位于
PATH中 - 使用
xgithub命令时需要 GitHub Personal Access Token
安装
使用 pip 安装:
python -m pip install xgit-utils
也可以使用 pipx 安装,以隔离命令行工具的运行环境:
pipx install xgit-utils
安装后可使用四个命令:xgit(命令组)、xclone、xsync 和 xgithub。每个命令都支持 --help,可查看完整参数列表。独立命令与 xgit 子命令的功能相同。
克隆仓库
克隆单个仓库:
xclone https://github.com/owner/repository.git
从文本文件中逐行读取并克隆仓库(每行一个 URL,空行会被忽略):
xclone repos.txt --target-dir ~/Mirror/github
也可以使用命令组:
xgit clone repos.txt
仓库会以 Git mirror 形式克隆到目标目录,并按 URL 路径分组。默认目标目录为 ~/Mirror/github,可通过 --target-dir 指定其他位置。
传入 --ignore 后,程序会将给定的 URL 写入 ~/.xgit/.xgitignore,而不执行克隆。之后克隆时会跳过该文件中列出的 URL。
同步仓库
获取目标目录下所有镜像仓库的更新:
xsync
常用参数:
xsync --repo okhttp # 只同步 URL 中包含“okhttp”的仓库
xsync --filter-host github.com # 只同步来自该主机的仓库
xsync --filter-host github.com --filter-host gitlab.com
xsync --list-remote # 列出本地镜像中的远程主机
xsync --list-repo # 列出本地镜像及其占用空间
xsync --export # 将仓库 URL 导出到文本文件
xsync --thread 4 # 设置并发同步数
默认目标目录为 ~/Mirror/github,默认线程数为 6。也可以通过 xgit sync 使用这些参数。
管理 GitHub 仓库
建议将 Token 设置为环境变量,避免保存在 shell 命令历史中:
export GITHUB_TOKEN="your-token"
列出已加星标的仓库(默认操作):
xgithub
列出自己的仓库或指定用户的仓库:
xgithub --mine
xgithub --user octocat
将自己的仓库克隆到目标目录,或将所选仓库列表导出为 HTML 文件(保存到当前目录):
xgithub --mine --clone
xgithub --user octocat --export
也可以通过 --token 直接传入 Token。通常使用 GITHUB_TOKEN 环境变量更方便。也可以通过 xgit github 使用这些参数。
代理
所有命令都支持 --use-proxy(或 -u)和 --proxy(或 -p)。默认代理地址为 127.0.0.1:1087:
xclone repos.txt --use-proxy --proxy 127.0.0.1:1087
开发
安装项目及开发依赖:
python -m pip install -e ".[dev]"
使用 Black 格式化 Python 代码:
python -m black .
仓库中的 VS Code 设置会选用 Black Formatter,并在保存 Python 文件时自动格式化。Black 的行宽配置读取自 pyproject.toml。
构建源码分发包和 wheel:
python -m build
Metadata
Release files for xgit-utils 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xgit_utils-1.0.1.tar.gz | 159.4 kB | With provenance | Details for xgit_utils-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xgit_utils-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for xgit_utils-1.0.1-py3-none-any.whl |
Total release size: 250.0 kB
Release files / xgit_utils-1.0.1.tar.gz
| Download URL | xgit_utils-1.0.1.tar.gz |
|---|---|
| Size | 159.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1667e623d5132aee8980c02383add491faa218f7bd6472103c9a6e4dbb518d75
|
|
BLAKE2b-256 checksum How to use checksums |
776c66eef498c4afab799d2ffd8b0ea3de27f23d3da32ce9292490a5455466f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logRelease files / xgit_utils-1.0.1-py3-none-any.whl
| Download URL | xgit_utils-1.0.1-py3-none-any.whl |
|---|---|
| Size | 90.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f31e1d972f57f7392a65a904b9a732a74a37808d3da1e747f52cfee3ed640809
|
|
BLAKE2b-256 checksum How to use checksums |
bcf19ad5175c1efec9ed12b1e48764928aff6372342a6141d1a26d910d7674a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logSecurity for xgit-utils 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for xgit_utils-1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.