GitHub Issue を作成し、ブランチを作るところまで CLI で完結させる

つまづくところなどありません。
GitHub CLI を使い、Issue を作り、作成した Issue からブランチを作成する話です。
早速作ります。

Issue を作る

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$ gh issue create -t "GitHub Issue から branch を作成するところまで CLI で 行う"

Creating issue in otokichi3/otokichi-tech

? Body <Received>
? What's next? Submit
https://github.com/otokichi3/otokichi-tech/issues/3
$ gh issue develop 3 -b main -c
github.com/otokichi3/otokichi-tech/tree/3-github-issue-から-branch-を作成するところまで-cli-で行う
From https://github.com/otokichi3/otokichi-tech
 * [new branch]      3-github-issue-から-branch-を作成するところまで-cli-で行う -> origin/3-github-issue-から-branch-を作成するところまで-cli-で行う

1つ目のコマンドは、単に -t オプションでタイトルを指定して Issue を作成しているだけです。
2つ目のコマンドが面白いですね。develop ですって。
issue は問題なので fix する方がしっくり来ますが、ともあれ develop の後に Issue 番号もしくは URL、そしてベースブランチを -b オプションで指定します。
最後の -c オプションは checkout のオプションです。そのブランチをチェックアウトします。

develop コマンドは物珍しかったので help を貼っておきます。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
$ gh issue develop --help
Manage linked branches for an issue.

When using the `--base` flag, the new development branch will be created from the specified
remote branch. The new branch will be configured as the base branch for pull requests created using
`gh pr create`.


USAGE
  gh issue develop {<number> | <url>} [flags]

FLAGS
  -b, --base string          Name of the remote branch you want to make your new branch from
      --branch-repo string   Name or URL of the repository where you want to create your new branch
  -c, --checkout             Checkout the branch after creating it
  -l, --list                 List linked branches for the issue
  -n, --name string          Name of the branch to create

INHERITED FLAGS
      --help                     Show help for command
  -R, --repo [HOST/]OWNER/REPO   Select another repository using the [HOST/]OWNER/REPO format

EXAMPLES
  # List branches for issue 123
  $ gh issue develop --list 123
  
  # List branches for issue 123 in repo cli/cli
  $ gh issue develop --list --repo cli/cli 123
  
  # Create a branch for issue 123 based on the my-feature branch
  $ gh issue develop 123 --base my-feature
  
  # Create a branch for issue 123 and checkout it out
  $ gh issue develop 123 --checkout
  
  # Create a branch in repo monalisa/cli for issue 123 in repo cli/cli
  $ gh issue develop 123 --repo cli/cli --branch-repo monalisa/cli

LEARN MORE
  Use `gh <command> <subcommand> --help` for more information about a command.
  Read the manual at https://cli.github.com/manual
  Learn about exit codes using `gh help exit-codes`

感想

何がいいかというと、CLI で完結させられる点です。GUI を持つ SourceTree や VSCode などのアプリケーション上でやっても結構ですが、コマンドを打つのはエンジニアらしくで気持ちがいいですね。それだけです。

余談

当たり前ですが、Pull Request の作成とマージまで CLI で完結します。以下はその記録です。 --fill-verbose オプションをつけると PR のタイトルと本文も書いてくれます。便利。 ところで issue タイトルがブランチ名になるので、issue タイトルは英語にしておきましょう。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
$ gh pr create --assignee @me --fill-verbose
Warning: 1 uncommitted change

Creating pull request for 4-hugo-papermod-の-config-を-toml-にて行う into main in otokichi3/otokichi-tech

https://github.com/otokichi3/otokichi-tech/pull/5
$ gh pr merge --merge --delete-branch
✓ Merged pull request otokichi3/otokichi-tech#5 (4 hugo papermod の config を toml にて行う)
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (1/1), 967 bytes | 483.00 KiB/s, done.
From https://github.com/otokichi3/otokichi-tech
 * branch            main       -> FETCH_HEAD
   ab62f6b..c02990c  main       -> origin/main
Updating ab62f6b..c02990c
Fast-forward
 content/posts/papermod-with-toml-config.md | 45 +++++++++++++++++++++++++++++++++++++++++++++
 hugo.toml                                  | 46 ++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 87 insertions(+), 4 deletions(-)
 create mode 100644 content/posts/papermod-with-toml-config.md
✓ Deleted local branch 4-hugo-papermod-の-config-を-toml-にて行う and switched to branch main
✓ Deleted remote branch 4-hugo-papermod-の-config-を-toml-にて行う
Hugo で構築されています。
テーマ StackJimmy によって設計されています。