再現性があるのか分からんがメモっておく
無事 master ブランチにマージされたので、どのようにやったかをメモっておく。
きっかけ
うなすけパイセンができるっつったら、できなくてもできるんだよ!!(壊れる可能性あり)
実際にやったこと
git clone
ができなかった
2 Above the list of files, click Code.
3 To clone the repository using HTTPS, under "Clone with HTTPS", click . To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, click Use SSH, then click . To clone a repository using GitHub CLI, click Use GitHub CLI, then click .
とあるので、PR#2362 の Code をポチっとすると
git clone
ではない何かが表示された。
というか「gh
is 何?」という気持ちでいっぱいになった。
gh
コマンドをインストールする
Code をクリックすると gh pr checkout 2362
なるコマンドの実行を促す吹き出しの下部に Learn more リンクが貼ってあるので、そのリンクに飛んでみる。
Install for Linux ボタン*1をクリックすると以下に飛ぶ。
俺の環境は elementary OS 6 だけど大体 Ubuntu なのでこれをやればいいのだろう。
$ curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg [sudo] jinroq のパスワード: 3+1 レコード入力 3+1 レコード出力 1795 bytes (1.8 kB, 1.8 KiB) copied, 0.000125439 s, 14.3 MB/s $ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null $ sudo apt update ヒット:1 http://dl.google.com/linux/chrome/deb stable InRelease 取得:2 https://cli.github.com/packages stable InRelease [3,743 B] ヒット:3 http://packages.microsoft.com/repos/code stable InRelease ヒット:4 http://ppa.launchpad.net/elementary-os/stable/ubuntu focal InRelease 取得:5 https://cli.github.com/packages stable/main amd64 Packages [337 B] 取得:6 http://mirrors.ubuntu.com/mirrors.txt Mirrorlist [450 B] ヒット:9 http://ppa.launchpad.net/elementary-os/os-patches/ubuntu focal InRelease ヒット:7 http://ftp.riken.jp/Linux/ubuntu focal InRelease 取得:8 http://ubuntu-ashisuto.ubuntulinux.jp/ubuntu focal-updates InRelease [114 kB] 取得:14 http://ftp.riken.jp/Linux/ubuntu focal-updates/universe amd64 DEP-11 Metadata [357 kB] 無視:11 http://ftp.jaist.ac.jp/pub/Linux/ubuntu focal-updates/main amd64 DEP-11 Metadata 無視:13 http://ftp.jaist.ac.jp/pub/Linux/ubuntu focal-updates/universe amd64 Packages 無視:10 https://jp.mirror.coganng.com/ubuntu focal-updates/main amd64 Packages 無視:10 http://ftp.tsukuba.wide.ad.jp/Linux/ubuntu focal-updates/main amd64 Packages 取得:15 https://jp.mirror.coganng.com/ubuntu-ports focal-updates/multiverse amd64 DEP-11 Metadata [944 B] 取得:12 http://archive.ubuntu.com/ubuntu focal-updates amd64 Contents (deb) [75.2 MB] 無視:10 http://ubuntutym.u-toyama.ac.jp/ubuntu focal-updates/main amd64 Packages 取得:11 https://jp.mirror.coganng.com/ubuntu-ports focal-updates/main amd64 DEP-11 Metadata [277 kB] 無視:13 https://jp.mirror.coganng.com/ubuntu-ports focal-updates/universe amd64 Packages 無視:10 http://mirror.fairway.ne.jp/ubuntu focal-updates/main amd64 Packages 無視:13 http://mirror.fairway.ne.jp/ubuntu focal-updates/universe amd64 Packages 取得:10 http://ftp.riken.jp/Linux/ubuntu focal-updates/main amd64 Packages [1,346 kB] 無視:13 http://ubuntutym.u-toyama.ac.jp/ubuntu focal-updates/universe amd64 Packages 無視:13 http://ftp.tsukuba.wide.ad.jp/Linux/ubuntu focal-updates/universe amd64 Packages 無視:13 https://jp.mirror.coganng.com/ubuntu focal-updates/universe amd64 Packages 無視:13 http://ubuntu-ashisuto.ubuntulinux.jp/ubuntu focal-updates/universe amd64 Packages 取得:13 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [877 kB] 78.2 MB を 27秒 で取得しました (2,895 kB/s) パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 パッケージはすべて最新です。 $ sudo apt install gh パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 以下のパッケージが新たにインストールされます: gh アップグレード: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。 7,300 kB のアーカイブを取得する必要があります。 この操作後に追加で 30.3 MB のディスク容量が消費されます。 取得:1 https://cli.github.com/packages stable/main amd64 gh amd64 2.2.0 [7,300 kB] 7,300 kB を 3秒 で取得しました (2,809 kB/s) 以前に未選択のパッケージ gh を選択しています。 (データベースを読み込んでいます ... 現在 174920 個のファイルとディレクトリがインストールされています。) .../archives/gh_2.2.0_amd64.deb を展開する準備をしています ... gh (2.2.0) を展開しています... gh (2.2.0) を設定しています ...できたっぽい。 man-db (2.9.1-1) のトリガを処理しています ...
インストールできたっぽい。
GitHub アカウントで認証する
インストールした後に何をやればいいのか何も書いてないので README を見てみた。
This folder is used for documentation related to developing gh. Docs for gh installation and usage are available at https://cli.github.com/manual.
素っ気ない。ひとまずマニュアルがあるらしいのでそちらを見てみる。
- Run gh auth login to authenticate with your GitHub account. Alternatively, gh will respect the GITHUB_TOKEN environment variable.
- To set your preferred editor, use gh config set editor
. Read more about gh config and environment variables. - Declare your aliases for often-used commands with gh alias set.
こう書いてあるので素直に従う。
$ gh auth login ? What account do you want to log into? GitHub.com ? What is your preferred protocol for Git operations? HTTPS ? Authenticate Git with your GitHub credentials? No ? How would you like to authenticate GitHub CLI? Login with a web browser ! First copy your one-time code: ****-**** - Press Enter to open github.com in your browser... 既存のブラウザ セッションで開いています。 mesa: for the --simplifycfg-sink-common option: may only occur zero or one times! mesa: for the --global-isel-abort option: may only occur zero or one times! mesa: for the --amdgpu-atomic-optimizations option: may only occur zero or one times! mesa: for the --structurizecfg-skip-uniform-regions option: may only occur zero or one times! [43568:43568:0100/000000.366560:ERROR:sandbox_linux.cc(376)] InitializeSandbox() called with multiple threads in process gpu-process. ✓ Authentication complete. Press Enter to continue... - gh config set -h github.com git_protocol https ✓ Configured git protocol ✓ Logged in as jinroq
CLI ベースで色々選択肢を選ぶよう促される。スクショを撮り忘れたのでログだけ載せておく。なんとなくの記憶では
- GitHub.com か Enterprise かを聞かれたので GitHub.com を選択
- HTTPS か SSH かはたまたほにゃららか*2を聞かれたので HTTPS を選択
- クライアントクレデンシャルズフロー的なやつにするか?と聞かれたので No を選択
- 認証は SMS でやるか、ブラウザでやるか、はたまたほにゃららか?と聞かれたのでブラウザを選択
項目 4 で新規ブラウザ画面がたちあがり、8 桁のコードを入力するよう促されるので、コンソール上の ! First copy your one-time code:
に表示されている 8 桁のコードを入力する。
認可を求められるので Authorize github をクリックする。
できたっぽい。
ついでに、gh
コマンドで使うエディタを Emacs にしておいた。
$ gh config set editor emacs
gh
コマンドを実行する
ようやく念願の gh
コマンドを実行できる時がきた。
$ gh pr checkout 2362 ? Which should be the base repository (used for e.g. querying issues) for this directory? ruby/www.ruby-lang.org remote: Enumerating objects: 17, done. remote: Counting objects: 100% (9/9), done. remote: Total 17 (delta 9), reused 9 (delta 9), pack-reused 8 Unpacking objects: 100% (17/17), 6.87 KiB | 782.00 KiB/s, done. From https://github.com/ruby/www.ruby-lang.org * [new ref] refs/pull/2362/head -> add_kwarg3_doc Switched to branch 'add_kwarg3_doc'
これで自分のローカル環境に hachi8833 さんが作った add_kwarg3_doc ブランチを持ってくることが出来た。
修正を反映して git commit
する
PR#2362 で mame さんの指摘内容を反映して、git commit
する。
ここまでは良かった。
git push
できない!!
$ git push Username for 'https://github.com': jinroq Password for 'https://jinroq@github.com': remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information. fatal: Authentication failed for 'https://github.com/hachi8833/www.ruby-lang.org.git/'
まずは add_kwarg3_doc ブランチから git push
してみた。この時 GitHub にログインする Username と Password を入力したのだが、パスワード認証は 2021/08/13 に廃止されたらしく、「代わりに個人アクセストークンを使え」とのこと。
これに従って個人アクセストークンを作った。git push
再チャレンジ。
$ git push Username for 'https://github.com': jinroq Password for 'https://jinroq@github.com': remote: Permission to hachi8833/www.ruby-lang.org.git denied to jinroq. fatal: unable to access 'https://github.com/hachi8833/www.ruby-lang.org.git/': The requested URL returned error: 403
Username は同じだが、Password に個人アクセストークンを入力する。
まぁ、結果はご覧の通り「そうですよね…」という感想しか出てこない。結局 git push
する権限を hachi8833 さんにもらわないといけないし、そんなことを依頼するくらいなら「自分で修正してください」と頼んだ方が早い。
add_kwarg3_doc ブランチを git clone
して新規に PR を作成する
俺が思いついた手っ取り早い解決方法が「add_kwarg3_doc ブランチを git clone
して、GitHub の jinroq アカウントのリポジトリに git push
して PR を作る」だったので、これをやった。
$ git branch -c add_kwarg3_doc add_kwarg3_doc_copy $ git checkout add_kwarg3_doc_copy $ git config branch.add_kwarg3_doc_copy.remote https://github.com/jinroq/www.ruby-lang.org.git $ git config branch.add_kwarg3_doc_copy.pushremote https://github.com/jinroq/www.ruby-lang.org.git $ git config branch.add_kwarg3_doc_copy.remote origin $ git push
本当はもっと紆余曲折あったのだが、上手くいく一番少ない手数は多分これ。
この後 git rebase master
をしてコンフリクトしまくる訳だが、それはまた別のお話。
まとめ
gh
コマンドを使って PR 作成者の功績を奪わずに PR を作成できた- 他人が作った PR にどうしても
git push
したいなら、その PR 作成者に権限をもらう必要がある