tracking branchのremote URLをみるpropen
zsh 用関数の propen、これ便利です。コマンドラインからプルリクを開く https://t.co/msRZcEVNap pic.twitter.com/jA4HXxOJlx
— Naoya Ito (@naoya_ito) 2016, 1月 4
で知ったGitHub - 作業中ブランチのプルリクエストをブラウザで開く - Qiitaがとても便利なんですが、origin以外にpushしているとプルリクの作成ができない(すでにプルリクがある場合はリダイレクトされる)ので、tracking branchのremote urlを参照するやつを書いた
function propen() { local current_branch_name=$(git symbolic-ref --short HEAD | xargs perl -MURI::Escape -e 'print uri_escape($ARGV[0]);') local remote=$(git branch -vv | grep '^*' | awk '{ print $4 }' | cut -d/ -f1 | sed -e 's/^\[//') local repo_url=$(git remote show -n $remote | grep 'Push URL' | grep -E -o '[^ ]+$' | sed -e 's|^https://||' -e 's/^git@//' -e 's/\.git$//' -e 's|:|/|') open "https://${repo_url}/pull/${current_branch_name}" }
$ git remote add fork git@github.com:ryotarai/itamae.git $ git push -u fork awesome-feature $ propen
とか叩くと、https://github.com/ryotarai/itamae/pull/awesome-feature
が開く