用于智能创建分支名称的 Git CLI 工具
Git CLI tool for intelligently creating branch names

原始链接: https://github.com/ytreister/gibr

## gibr:更智能的 Git 分支命令行工具 gibr 通过连接你的问题追踪器(目前支持 GitHub、GitLab、Jira 和 Linear)来简化 Git 工作流程,从而创建一致且具有描述性的分支名称。它简化了分支创建,允许你直接引用问题编号——例如 `gibr 123`——并根据问题详情自动生成分支名称。 使用 `gibr init` 可以轻松设置,它会引导你配置问题追踪器并创建 `.gibrconfig` 文件。你还可以使用 `gibr alias` 为 `git` CLI 扩展别名,用于诸如 `git create 123` 之类的命令。 gibr 支持使用占位符(如 `{issuetype}`、`{issue}` 和 `{title}`)自定义分支名称格式。它处理问题列表(`gibr issues` 或 `git issues`)和分支创建,包括检出和推送到 origin。 更多信息,请查看路线图、贡献指南或在项目仓库中打开 issue。

## Hacker News 讨论:Git 分支命名工具与最佳实践 最近 Hacker News 上有一篇帖子讨论了一个新的 Git 命令行工具,用于智能创建分支名称 ([https://github.com/ytreister](https://github.com/ytreister))。讨论很快演变成关于分支命名的*最佳*实践的争论。 许多评论者认为,过于详细的分支名称是不必要的,因为分支通常生命周期很短。一个常见的建议是使用用户标识符作为分支前缀,以便跟踪所有权,并优先考虑清晰简洁的提交信息。将分支链接到问题/工单编号(例如 `ISSUE-9482` 或 `issue-10-add-feature-X`)也很受欢迎,尤其是在与 Linear 和 Jira 等项目管理工具集成时,这些工具可以自动链接 PR 和问题。 一些人提倡更结构化的命名约定,如 `feature/username/id-desc`,而另一些人则更喜欢最简命名——甚至 UUID,依靠 PR 描述和提交历史记录来提供上下文。一个关键的争论点是是否在合并前压缩提交,一些人认为在审查期间需要详细的原子提交,而另一些人则倾向于压缩以获得更清晰的历史记录。最终,共识倾向于简单和实用性,优先考虑使团队合作和代码审查更容易的方法。
相关文章

原文

Tests Coverage PyPI version Downloads Python versions License GitHub stars GitHub issues

🧩 A smarter CLI for creating Git branches.

gibr connects your Git workflow to your issue tracker — instantly creating consistent, descriptive branches. Fully configurable, and ready for any tracker or team setup.

Currently supporting integration with:

GitHub GitLab Jira Linear

# List open issues
$ gibr issues
|   Issue | Type   | Title                                 |
|---------|--------|---------------------------------------|
|     123 | issue  | Add support for OAuth2 / login (beta) |
|      97 | issue  | Add support for gitlab                |
# Decide which issue to work
$ gibr 123
Generating branch name for issue #123: Add support for OAuth2 / login (beta)
Branch name: issue/123/add-support-for-oauth2-login-beta
✅  Created branch 'issue/123/add-support-for-oauth2-login-beta' from main.
✅  Checked out branch: issue/123/add-support-for-oauth2-login-beta
✅  Pushed branch 'issue/123/add-support-for-oauth2-login-beta' to origin.
uv pip install gibr
# or
pip install gibr

Run gibr init to set up your configuration interactively. This will create a .gibrconfig file in your project root with the correct format for your chosen issue tracker.

Setup git aliases commands (optional)

Run gibr alias to set up git alias commands for your conveinence. This essentially allows you to extend the git CLI with gibr commands. See alias command for more details

gibr includes an init command to help you create your .gibrconfig file. See the following usage example:

$ gibr init
Welcome to gibr setup! Let’s get you started 🚀

Which issue tracker do you use?
1. GitHub
2. GitLab
3. Jira
4. Linear
5. Monday.com (coming soon)

Select a number (1, 2, 3, 4, 5) [1]: 1

GitHub selected.

GitHub repository (e.g. user/repo): ytreister/gibr
Environment variable for your GitHub token [GITHUB_TOKEN]:
🎉  Found GitHub token in environment (GITHUB_TOKEN)
.gibrconfig already exists. Overwrite? [y/N]: y
✅  Created .gibrconfig with GitHub settings
You're all set! Try: `gibr issues`

gibr includes a built-in helper that writes git aliases into your global ~/.gitconfig for you. Run:

This adds aliases such as git create so that instead of using the gibr CLI directly, you can use an extended version of git:

The above command is equivalent to using the CLI as follows: gibr 123 or gibr create 123.

The flag order when using the git alias version is different:

# ✅ gibr CLI (flags before)
gibr --verbose create 123

# ✅ git alias (flags after)
git create 123 --verbose

# ❌ wrong: flags after gibr CLI
gibr create 123 --verbose 

# ❌ wrong: flags before the alias
git --verbose create 123

Run gibr issues (or git issues) to view open issues in the issue tracker you have configured

Run gibr 123 (or gibr create 123 or git create 123) to create a branch for the cooresponding issue number.

gibr uses the branch_name_format from your .gibrconfig to determine the format for the branch. You can use the following placeholders: {issuetype}, {issue}, {title}.

For Jira, you can specify a project_key in your configuration:

If you do this, you can choose to either specify the entire issue id or just the numerical portion (i.e. FOO-123 or 123

# List issues
$ gibr issues
| Issue   | Type    | Title       |
|---------|---------|-------------|
| FOO-3   | Subtask | Subtask 2.1 |
| FOO-2   | Story   | Task 2      |
# Create branch for FOO-3
$ gibr 3
Generating branch name for issue FOO-3: Subtask 2.1
Branch name: FOO-3-subtask-2-1
✅  Created branch 'FOO-3-subtask-2-1' from main.
✅  Checked out branch: FOO-3-subtask-2-1
✅  Pushed branch 'FOO-3-subtask-2-1' to origin.
  • --verbose — enable debug-level logging for a command

See the Roadmap for upcoming features and plans.

See the Contributions guidelines if you would like to contribute.

Found a bug or have a feature request? Open an issue or start a discussion.
If you find it useful, consider starring ⭐️ the repo — it really helps visibility!

联系我们 contact @ memedata.com