LoginSignup
0
0

More than 3 years have passed since last update.

git checkout とか git push のときに、ブランチ名をコピーするのが面倒なとき

Posted at

ホームディレクトリ配下の.gitconfigに以下の設定を書いておくと、git jumpとかgit bcpと打ち込むだけで、移動したり、ブランチ名をコピーできます。
ただし、pecoコマンドが入っているのでインストールはお忘れなきよう。

~/.gitconfig
[alias]
  jump = !git checkout $(git branch | sed 's/*//g' | sed 's/ //g' | peco)
  bcp  = !git branch | peco | sed 's/*//g' | sed 's/ //g' | tr -d '\n'  | pbcopy

なお、!について、ですが、StackOverFlowによると、

If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command.

!がついてると、shell commandとして見做すということだそうです。
(ついてないと→な感じのエラーが出ます。expansion of alias 'bcp' failed; 'git' is not a git command)。

0
0
0

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
0
0