Using Gh to Create a Branch for an Issue

The CLI utility gh allows you to create a branch associated with an issue, even if in another repository.

TL;DR

# creates a branch in repo bomb for issue 170 in repo nails
❯ gh issue develop 179 --repo acme/nails
    --branch-repo acme/bomb
    --checkout
github.com/acme/bomb/tree/179-i-got-a-brilliant-idea

GH is very useful for working with Github projects

Github Projects is a substandard tool for managing issues - mostly because feature poor and not in active development. But it’s free and works well with the gh CLI utility. Its most compelling feature, however, is probably the fact that it’s not Jira. We have been using it at work until we became large enough to migrate to better tooling, in our case Linear.

Using gh with Github Projects

There are a few commands that you can use with the gh CLI utility:

Here are a couple I use all the time

View work in the browser

❯ gh issue view 123 -w
❯ gh pr view -w
❯ gh repo view -w

These are all similar, and they open an issue / the current PR / the current repo in a web browser

Toggle draft / ready for work for a PR

# make the PR ready
❯ gh pr ready

# make the PR a draft
❯ gh pr ready --undo

Odd syntax, but whatever

Checkout a new branch for an issue in another branch

And the biggest time saver of them all, which create a branch associated with an issue in another repo, and checks it out too.

❯ gh issue develop 179 --repo acme/nails
    --branch-repo acme/bomb
    --checkout
github.com/acme/bomb/tree/179-i-got-a-brilliant-idea

Hope these are helpful to you.


Got thoughts on this post? Join the conversation on Mastodon!