2
1

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.

Gitで現在のブランチ名をコピーするコマンドを作る

2
Last updated at Posted at 2019-11-18

gitを使っていると、今いるブランチ名をコピーしたい時があります
そんな時に使える便利コマンドを作ります。

環境

Macを想定しています。windowsの場合は pbcopy の部分をwindowsのコピーコマンドに置き換える必要があります。

コマンドの作成

gitはパスの通ったフォルダに git-hogehogeに従った命名規則のファイルを置くと、サブコマンドとして認識します。これを利用してコマンドを作成します。

vim /usr/local/bin/git-copy-branch 
/usr/local/bin/git-copy-branch
# !/bin/bash
git name-rev --name-only HEAD | pbcopy
chmod +x /usr/local/bin/git-copy-branch 

使用法

以下のコマンドで先ほど作成したコマンドが呼び出されます。

git copy-branch
2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?