{"id":22196581,"url":"https://github.com/planjs/git-cli","last_synced_at":"2025-07-20T14:37:33.185Z","repository":{"id":57683418,"uuid":"474943869","full_name":"planjs/git-cli","owner":"planjs","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-02T14:42:27.000Z","size":332,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-19T19:06:20.148Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/planjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-28T10:01:43.000Z","updated_at":"2022-05-29T04:45:09.000Z","dependencies_parsed_at":"2022-09-15T18:12:26.147Z","dependency_job_id":null,"html_url":"https://github.com/planjs/git-cli","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/planjs/git-cli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planjs%2Fgit-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planjs%2Fgit-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planjs%2Fgit-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planjs%2Fgit-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/planjs","download_url":"https://codeload.github.com/planjs/git-cli/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/planjs%2Fgit-cli/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266142123,"owners_count":23883038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T14:15:28.050Z","updated_at":"2025-07-20T14:37:33.163Z","avatar_url":"https://github.com/planjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @planjs/git-utils\n一个可编程和命令行的git工具集合, 基于 `nodegit` 组件包开发。\n\n### 安装\n```\nsudo npm i -g @planjs/git-utils --unsafe-perm=true\n# or\nnpm i -D @planjs/git-utils\n```\n\n## cli 方式调用\n\n##### `--check=branch` 检测当前分支是否正确\n```bash\ngt --check=test\n```\n如果当前分支不是 `test` 将会报错\n\n\n#### `--autoMerge=targerBranch` 切换目标分支并且合并\n```bash\ngt --autoMerge=develop\n```\n将当前分支合并到`develop`并且将本地分支切换到`develop`分支，失败条件：合并存在冲突、本地分支存在为commit内容。\n\n#### `--check=branch --entry=/project` 指定仓库目录地址\n```bash\ngt --autoMerge=develop --entry=/project\n```\nentry参数可以指定所在仓库目录地址\n\n## Node Api\n#### 使用例子\n\n```javascript\nimport GT, { openRepository } from '@quan/git-utils';\nconst repo = GT({ autoMerge: 'develop' })\n```\n\n###### `gitUtils(options: { check?: string, autoMerge?: string, entry?: string })`\n与命令行行为一致\n\n\n###### `openRepository(path?: string): Promise\u003cGit.Repository\u003e`\n打开一个git仓库，path 参数为仓库目录路径。\n\n###### `checkNotCommit(repo: Git.Repository): Promise\u003cGit.Repository\u003e`\n检测本地分支是否存在为保存内容。\n\n###### `function pull(repo: Git.Repository): Promise\u003cGit.Repository\u003e`\n拉取远程仓库内容\n\n###### `function switchBranch(repo: Git.Repository,name: string): Promise\u003cGit.Repository\u003e`\n切换到对应分支\n\n###### `mergeBranch(repo: Git.Repository,fromBranch: string): Promise\u003cGit.Repository\u003e `\n合并对应的分支，如果发生冲突会合并失败。\n\n###### `function push(repo: Git.Repository)`\n推送到远程仓库中\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanjs%2Fgit-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplanjs%2Fgit-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplanjs%2Fgit-cli/lists"}