くりにっき

フルスタックキュアエンジニアです

「GitHubのPull Requestを簡単にチェックアウトするたった1つの方法」のaliasを作った

元ネタ

sinsoku.hatenablog.com

便利なんですがコマンド長すぎて覚えられないのでaliasにしました

.gitconfig

[alias]
  fpr = "!f() { git fetch origin pull/$1/head:pr/$1; }; f"

コマンド名が気になる人は適宜変えてください

使い方

git fpr <PullRequest ID>

pr/<PullRequest ID> にbranchが作られます

使った図

[sueyoshi_go@YG41-08546.local] ✓ ~/workspace/github.com/sue445/chrome-gitlab-notifier (master)
[sueyoshi_go@YG41-08546.local] [03-31 16:01:18] $ g fpr 83
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 14 (delta 4), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
From github.com:sue445/chrome-gitlab-notifier
 * [new ref]         refs/pull/83/head -> pr/83

[sueyoshi_go@YG41-08546.local] ✓ ~/workspace/github.com/sue445/chrome-gitlab-notifier (master)
[sueyoshi_go@YG41-08546.local] [03-31 16:02:18] $ g co pr/83
Switched to branch 'pr/83'

[sueyoshi_go@YG41-08546.local] ✓ ~/workspace/github.com/sue445/chrome-gitlab-notifier (pr/83)
[sueyoshi_go@YG41-08546.local] [03-31 16:02:46] $

【おまけ】.gitconfig の aliasで登録したコマンドから引数を取得する方法

直接 $1 って書くとうまく動かなかったので調べたら関数の中に入れる必要があるっぽい

stackoverflow.com