Github公式の解説では3つほどコマンドをうってチェックアウトをする方法が紹介されているがIDであったりブランチ名を調べる必要があって少しめんどくさい。
そこで今日使ってみたのがhubコマンド。自分の中ではこのシーンを解決するのにhubコマンドが結局最強だった。 hubコマンドはGithubが開発・メンテナンスをしているオフィシャルなCLIツールです。
% hub --version git version 2.23.0 hub version 2.12.8 % hub pr Usage: hub pr list [-s <STATE>] [-h <HEAD>] [-b <BASE>] [-o <SORT_KEY> [-^]] [-f <FORMAT>] [-L <LIMIT>] hub pr checkout <PR-NUMBER> [<BRANCH>] hub pr show [-uc] [-h <HEAD>] hub pr show [-uc] <PR-NUMBER>
まず、hub pr list
で現在のPull Requestの一覧が取得する。
次にhub pr checkout <ID> [<local branch name>]
でPull Requestをローカルにチェックアウトする。
# PR 一覧を取得 % hub pr list #439 ORC-557 Fix problem reading large header with uncompressed streams. #435 ORC-557: Fix the issue when orc-tool opens the huge file over 4GB #308 Covert tool should create a lowercase schema #283 ORC-378 #189 ORC-210 Add new encodings and benchmarks for new double encoding. #179 ORC-255 #161 ORC-210: Add encoding for Double, Float. #142 [ORC-218] Cache timezone information in the library. #101 ORC-156 # PRを指定してチェックアウト % hub pr checkout 283 remote: Enumerating objects: 49, done. remote: Counting objects: 100% (49/49), done. remote: Total 110 (delta 48), reused 48 (delta 48), pack-reused 61 Receiving objects: 100% (110/110), 26.30 KiB | 124.00 KiB/s, done. Resolving deltas: 100% (48/48), completed with 16 local objects. From https://github.com/apache/orc * [new ref] refs/pull/283/head -> master-378 Switched to branch 'master-378' % hub branch master * master-378 # PRとローカルブランチ名を指定してチェックアウト % hub pr checkout 439 omalley-orc-557 remote: Enumerating objects: 17, done. remote: Counting objects: 100% (17/17), done. remote: Compressing objects: 100% (8/8), done. remote: Total 17 (delta 5), reused 15 (delta 5), pack-reused 0 Unpacking objects: 100% (17/17), done. From https://github.com/apache/orc * [new ref] refs/pull/439/head -> omalley-orc-557 Switched to branch 'omalley-orc-557' % hub branch master master-378 * omalley-orc-557
hubコマンド簡単でしたね。これでGithubでの開発ライフが捗りますね〜 Enjoy happy development life.
2020/04/04 追記
aliasを作っておくとさらに捗る。
$ git config --global --add alias.b "browse" $ git config --global --add alias.prl="pr list" $ git config --global --add alias.prco="pr checkout"