How to use Github CLI in 7 commands
thomasvanholder
Posted on November 4, 2021
- Open project in Github
- List all issues
- Create new issue
- List all PRs
- Check PR status
- Merge PR into main
- Switch between branches
Github CLI installed?
Check by running gh version
1. Open project in Github
Open the github homepage of the current project in the browser.
gh browse
Github CLI's response:
Opening github.com/repo/my-repo in your browser.
2. List all issues
Return all outstanding issues in the repository.
gh issue list
Github CLI's response:
Showing 3 of 3 open issues in repo/my-repo
#178 bug when downloading pdf about 3 minutes ago
#166 refactor stripe api call about 2 days ago
#126 depreciate pacakge 20 days ago
3. Create new issue
Did you find a new bug?
Add something as a to-do for later on Github Issues. The CLI will prompt you a few questions.
gh issue create
Github CLI's response:
Creating issue in repo/my-repo
? Title bug when downloading pdf
? Body <Received>
? What's next? Submit
https://github.com/repo/my-repo/issues/178
4. List all PRs
Retrieve an overview of all PR in the repository.
gh pr list
Github CLI's response:
Showing 3 of 3 open pull request in repo/my-repo
#170 feat/stripe-checkout
#142 feat/vitally-api
#139 bug/profile-responsiveness
5. Check PR status
To find out if the PR passed the automated testing suite.
gh pr status
Github CLI's response:
Relevant pull requests in repo/my-repo
Current branch
#177 new-feature [new-feature]
ā Checks passing
6. Merge PR into main
A useful shortcut to easily delete a branch from both Github and your local enviroment.
2 options:
- From the local main branch
Merge a PR into the main branch by specifying the PR number.
gh pr merge 177
- From the PR branch
No need to specific the PR number.
gh pr merge
Github CLI's response:
? What merge method would you like to use? Create a merge commit
? Delete the branch locally and on GitHub? Yes
? What's next? Submit
ā Merged pull request #177 (new-feature)
ā Deleted branch new-feature
7. Switch between branches
This CLI command is based upon a popular extension.
Install the extension
gh extension install mislav/gh-branch
Run the extension.
gh branch
Move across branches with up and down arrow. Hit enter to select the branch.
Github CLI's response:
feat/stripe-checkout 6 weeks ago
feat/postmark-integration 2 weeks ago
> new-feature 25 hours ago
bug/profile-responsiveness 2 hours ago
4/4
Posted on November 4, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.