11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

tig でリモートブランチを checkout する

Last updated at Posted at 2014-03-19

やけに丁寧なtigのキーバインド設定ガイド で、リモートブランチを取得する設定が紹介されていた。
コマンドラインから叩くよりは楽なんだけど、checkout 先を入力する必要があるのがダルい。

そこで次のように設定してみた。

bind branch r !sh -ec 'b=`expr "%(branch)" : "origin/\(.*\)"`; git checkout -b $b %(branch)'

%(branch) で取れるブランチ名は origin/feature/test のようになっていて、除去したいので、!sh で shell を起動し、expr を経由させて、それをやっている。
更に、origin/ で始まっていない branch は対象外としたいので sh に -e オプションをつけている。

追記

-t/--track オプションを使うともっと簡単にできることをコメント欄で教えてもらった。
bind branch r ... は次のように書ける:

bind branch T !git checkout -t %(branch)

使い方

tig を起動し、H を押して、ブランチビューに移動する。

スクリーンショット 2014-03-19 22.51.08.png

そしてチェックアウトしたいブランチにカーソルを移して、r を押す。

スクリーンショット 2014-03-19 22.44.52.png

すると一旦以下のようになるので、言われたとおりに Enter を押す。

スクリーンショット 2014-03-19 22.45.43.png

feature/test がチェックアウトできた!

スクリーンショット 2014-03-19 22.46.46.png

ちなみに、origin/ で始まっていないブランチ (master branch とか) で r を実行しても、何もしない。

11
11
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?