gh
Using gh
as a credential manager
Section titled Using gh as a credential managerIf you find yourself having to change remotes of a repo in order to authenticate as the correct user, then perhaps you should consider using gh
as your credential manager.
- Run
gh auth setup-git
(reference). - Run
gh auth login
to login with however many accounts you have - Run
gh auth switch
to switch the current account - With this method, you don’t need
ssh-add
in your shell’src
file. - Note that if this doesn’t work with an error like this:
ERROR: Permission to Adam13531/AdamsApple.git denied to AdamLearns.
, then perhaps try changing your remote to be HTTPS rather than SSH. - Note that if you get an error about scopes (e.g.
! [remote rejected] main -> main (refusing to allow an OAuth App to create or update workflow `.github/workflows/produce-docker-image.yml` without `workflow` scope)
, you can login with the right scopes:gh auth login --scopes workflow
Pull requests
Section titled Pull requests- List all PRs:
gh pr list
- Start working locally on a PR: `gh pr checkout PR_NUMBER
- The next thing you should do isn’t
gh
-specific, but you should update the PR branch with eitherrebase
or amerge
.rebase
will rewrite the history and require a force-push since the base branch is in another repo. Merging can be done withgit merge --no-ff main
and will have the same effect without rewriting history.
- The next thing you should do isn’t
- Finish working on a PR:
git push
- Merge the PR on GitHub or via
gh pr merge
(without an argument, it will use the current branch). I prefer using GitHub for this.
Troubleshooting
Section titled Troubleshooting”Updates were rejected […]”
Section titled ”Updates were rejected […]”Full error:
This happens from the following flow:
gh pr checkout PR_NUMBER
git pull origin main --rebase
git push
The reason is that I’m pulling in myorigin
even though I’m working in someone else’s repo.