cli icon indicating copy to clipboard operation
cli copied to clipboard

Checkout branch for issue

Open sammarks opened this issue 3 years ago • 4 comments

Describe the feature or problem you’d like to solve

Right now, we can checkout branches related to PRs, but it doesn't look like that same functionality exists for issues (since GitHub web now allows you to automatically create branches associated with issues, before creating a PR).

Proposed solution

It would be nice if there were a new gh issue checkout {<number> | <url>} command. When called:

  • If a branch has already been created for that issue,
    • It checks out the branch.
  • If a branch has not already been created for that issue,
    • It calls GitHub API to create the branch automatically (does the API support this yet?)
    • It checks out the new branch.

It's beneficial because it allows developers to get started on new issues quickly using the CLI, rather than having to open the web interface and create the branch there first.

I would think this command should support the same options the gh pr checkout command has:

  • --branch for the local branch name.
  • --detach for detached HEAD
  • --force to reset to the remote branch.
  • --recurse-submodules

Additional context

Arguably, it's not that hard to workaround this. If the branch already exists, you can git fetch and tab-complete the issue number (as long as you're sticking with the default naming scheme). If the branch doesn't exist, you could create your own branch, but then the new branch you've created isn't connected with the issue (until you submit a PR?).

sammarks avatar Apr 15 '22 12:04 sammarks

@sammarks Thanks for the feature request. This is something that we want to implement in the future, we are still unsure of how we want to design it though, so we appreciate your proposal.

cc https://github.com/github/special-projects/issues/1219

samcoe avatar Apr 18 '22 09:04 samcoe

Describe the feature or problem you’d like to solve

Right now, we can checkout branches related to PRs, but it doesn't look like that same functionality exists for issues (since GitHub web now allows you to automatically create branches associated with issues, before creating a PR).

Proposed solution

It would be nice if there were a new gh issue checkout {<number> | <url>} command. When called:

  • If a branch has already been created for that issue,

    • It checks out the branch.
  • If a branch has not already been created for that issue,

    • It calls GitHub API to create the branch automatically (does the API support this yet?)
    • It checks out the new branch.

It's beneficial because it allows developers to get started on new issues quickly using the CLI, rather than having to open the web interface and create the branch there first.

I would think this command should support the same options the gh pr checkout command has:

  • --branch for the local branch name.
  • --detach for detached HEAD
  • --force to reset to the remote branch.
  • --recurse-submodules

Additional context

Arguably, it's not that hard to workaround this. If the branch already exists, you can git fetch and tab-complete the issue number (as long as you're sticking with the default naming scheme). If the branch doesn't exist, you could create your own branch, but then the new branch you've created isn't connected with the issue (until you submit a PR?).

Griffin641498 avatar Apr 22 '22 00:04 Griffin641498

Describe the feature or problem you’d like to solve

Right now, we can checkout branches related to PRs, but it doesn't look like that same functionality exists for issues (since GitHub web now allows you to automatically create branches associated with issues, before creating a PR).

Proposed solution

It would be nice if there were a new gh issue checkout {<number> | <url>} command. When called:

  • If a branch has already been created for that issue,

    • It checks out the branch.
  • If a branch has not already been created for that issue,

    • It calls GitHub API to create the branch automatically (does the API support this yet?)
    • It checks out the new branch.

It's beneficial because it allows developers to get started on new issues quickly using the CLI, rather than having to open the web interface and create the branch there first.

I would think this command should support the same options the gh pr checkout command has:

  • --branch for the local branch name.
  • --detach for detached HEAD
  • --force to reset to the remote branch.
  • --recurse-submodules

Additional context

Arguably, it's not that hard to workaround this. If the branch already exists, you can git fetch and tab-complete the issue number (as long as you're sticking with the default naming scheme). If the branch doesn't exist, you could create your own branch, but then the new branch you've created isn't connected with the issue (until you submit a PR?).

Griffin641498 avatar Apr 22 '22 00:04 Griffin641498

I think it would be quite practical if gh also gave us the option to create a branch after creating an issue in the "What's next?" dialog we're prompted with. My current workflow is creating the issue from cli, then select continue in browser, submitting issue, then pressing create branch. It would be quite smooth if I could complete the issue as normal from the cli, then selecting "create branch", which would create a branch in origin, fetch and checkout locally.

kriberg avatar Jun 28 '22 11:06 kriberg

This got shipped as gh issue develop https://github.com/cli/cli/pull/6254

mislav avatar Dec 20 '22 16:12 mislav