ghコマンドでgitを操作する

## はじめに
表題通り、ghコマンドでgitを操作します。

https://cli.github.com/

## インストール~ログインまで
```sh:brewでinstallする
brew install gh

```

```shell:Gitのログイン
~  $ gh auth login                                               
? Where do you use GitHub? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: 07CD-XXXX
Press Enter to open https://github.com/login/device in your browser... 
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as kouji0705

```
→ブラウザが起動するので、ログイン認証を実施します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/599049/977bbe6a-fc1c-53c1-b6b9-f75be9d841b1.png)


## 便利コマンド

```shell:PRの管理を表示する
~/develop/cli  (trunk)$ gh pr list                                                                                                                                                                                   (base) 

Showing 23 of 23 open pull requests in cli/cli

ID      TITLE                                                                                                        BRANCH                                                                         CREATED AT        
#10081  Update install_linux.md                                                                                      Tomaszek2902:patch-1                                                           about 5 hours ago
#10051  Use Windows compatible file name for downloaded attestations when running `gh attestation download`          malancas:gh-attestation-download-windows-bug                                   about 4 days ago
#10048  Fixing gh gist view prompts with no TTY                                                                      mateusmarquezini:fix/issue_10042                                               about 4 days ago
#10012  Perform all `gh attestation verify` policy options configuration in the `newEnforcementCriteria()` function  malancas:consolidate-verify-policy-options-config                              about 9 days ago
#10002  Allow argument to `gh repo set-default` to be the name of a remote                                           ADKaster:setdefault-remote                                                     about 9 days ago
#9998   Gh attestation verify options cleanup                                                                        malancas:gh-attestation-verify-options-cleanup                                 about 10 days ago
#9957   Implement git project description (`.git/description`)                                                       moritztim:description-file                                                     about 20 days ago
#9940   Rename local repo by `gh repo rename`                                                                        benebsiny:cli-9695                                                             about 23 days ago
#9934   Bring extension update logic up to par with gh update logic                                                  andyfeller/cli-cli-8183-timeout-pt2                                            about 25 days ago
#9868   feat: let user select pr to checkout                                                                         nilvng:nil/fix-2329                                                            about 1 month ago
#9847   [gh search issues] Support multiple author options                                                           Shion1305:shion/9828                                                           about 1 month ago
#9792   fix(workflow/run): check if workflow exists on the default branch to be run                                  arunsathiya:fix/9781-workflow-run-requirement-default-branch                   about 1 month ago
#9497   Fix `pr checkout`, cannot set up tracking info                                                               muzimuzhi:fix/pr-checkout-with-restricted-remote-fetch                         about 3 months ago
#9416   feat(ghinstance): allow port in host                                                                         nobe4:allow-hort-in-host                                                       about 4 months ago
#9339   fix #562 by adding a warning message when PR branch has diverged from local                                  Wires77:pr_checkout_messaging                                                  about 4 months ago
#9208   Find PRs using `@{push}`                                                                                     Frederick888:find-pr-by-rev-parse-push                                         about 6 months ago
#9083   add remote check to secret and variable commands                                                             wingleung:add-remote-check-to-secret-and-variable                              about 7 months ago
#9044   Fallback clone from user organization                                                                        maaslalani:fallback-organization                                               about 7 months ago
#9037   issue edit: avoid race conditions when editing assignees, reviewers                                          wingleung:issue-edit-avoid-race-conditions-when-editing-assignees,-reviewers-  about 7 months ago
#8826   feat: implement gh `pr revert`                                                                               lucasmelin:lucasmelin/add-pr-revert-command                                    about 9 months ago
#8718   feat: add `gh deployment` commands                                                                           sjparkinson:add-deployment                                                     about 9 months ago
#7743   Use native keychain bindings if possible                                                                     YorikSar:native-keyring                                                        about 1 year ago
#7322   feat(pr): Add cleanup subcommand to delete merged local branches                                             elldritch:feat/pr-cleanup                                                      about 1 year ago
~/develop/cli  (trunk)$                                                                                                                                                                 
```

```shell:PRをチェックアウトする
~/develop/cli  (trunk)$ gh pr checkout 10081                                                                                                                                                                         (base) 
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 1 (delta 0), pack-reused 0 (from 0)
Unpacking objects: 100% (1/1), 842 bytes | 280.00 KiB/s, done.
From https://github.com/cli/cli
 * [new ref]           refs/pull/10081/head -> patch-1
Switched to branch 'patch-1'
```


```shell:ブラウザで現在のgitを開く
gh browse
```