| title | How to Create a Branch from an Issue in Github (without the GUI / from the Command Line) | |||
|---|---|---|---|---|
| tags |
|
GitHub's CLI tool gh provides a convenient way to create branches linked to specific issues without using the GUI.
Prerequisite: Ensure you have the GitHub CLI (
gh) installed and authenticated.
gh issue list
Note: If there's no issue for you to work on, you can create one with
gh issue createfollowed by a few interactive prompts.
gh issue develop <issue-number> [--base <base-branch>] [--name <branch-name>] [--checkout]
gh issue develop: Will create a branch for you to work on that's connected to an issue<issue-number>: The number of the issue you want to link the branch to.--base <base-branch>: (Optional) The branch you want to base your new branch on. Defaults to the repository's default branch if not specified.--name <branch-name>: (Optional) The name for the new branch. If not provided, GitHub CLI generates a name based on the issue title.--checkout: Will switch to the branch after it creates it, saving you from having to run agit switch <branch-name>afterwards
Example: Createing a branch for issue #48, from the dev branch with a custom issue title:
# run command from the main branch
devin:~/repos/projects/serp-ui-nuxt (main)$
$ gh issue develop 32 --name ds/32/company-index --checkout
github.com/serpcompany/serp-ui-nuxt/tree/ds/32/company-index
From github.com:serpcompany/serp-ui-nuxt
* [new branch] ds/32/company-index -> origin/ds/32/company-index
# automatically switched to the created branch
devin:~/repos/projects/serp-ui-nuxt (ds/32/company-index)$
# List all issues (open and closed)
gh issue list --state all
# List issues assigned to you
gh issue list --assignee @me
# List issues with a specific label
gh issue list --label bug
# List issues in JSON format
gh issue list --json number,title,assignees
# List issues with custom columns
gh issue list --columns number,title,assignees,labels
# List issues and limit the output
gh issue list --limit 10
# List issues and sort them
gh issue list --sort comments
# List issues in web browser
gh issue list --web