As I try to move away from GUI’s and more into a text-based environment, I find myself coming to points where I need to stop and branch out my knowledge.
Currently when I’m finished with a feature or project, I need to rely on GitHub’s GUI for manipulating and managing my pull requests.
I’ve been fine with managing my code base this way until now and although the GitHub CLI can be a bit intimidating, it looks like a powerful tool and I’m excited to learn it.
The following responses are color-coded:
- Open
- Merged
- Deleted
List all open pull requests
gh pr list
To view all pull requests (past and present)
gh pr list --state "all"
# or shortened
gh pr list -s "all"
List assigned pull requests by user
gh pr list --assignee 'harryrf3'
Check pull request status
gh pr status
# responses -
# Current branch
# Created by you
# Requesting a code review from you
List closed pull requests
gh pr list --state 'closed'
# shortened
gh pr list -s 'closed'
List labeled pull requests
gh pr list --label 'bug'
# shortened
gh pr list -l 'bug'
Open pull requests from command line
# reference pr by number, branch, or url
gh pr view '3'
Create pull request for current branch
gh pr create -t 'PR_TITLE' -b 'PR_DESC_BODY'
Create pull request from browser
# when running into issues with the cli
gh pr create --web
Checkout branch for pull request
# checks out branch pull request is on
gh pr checkout 'PR_#'
Command line aliases for command line pull requests management
# list pull requests under 'bug' label
alias listprs='gh pr list --label "bug"'
# list pull requests that are assigned to me
alias listmyprs='gh pr list -a "harryrf3"'
Lastly, if you own or are a core contributor for a repository, you can merge your own pull requests.
Merge a pull request
gh pr merge 'PR_#'
# Responses:
# What merge method...? Create a merge commit
# Delete the branch...? Yes
# What's next? Submit
# append with --admin flag if merge is refused
REFERENCES
goobar - Use GitHub CLI For Command Line Pull Request Management$ gh pr –help
rietta.com - What’s the Difference Between the 3 Github Merge Methods?