8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

このブランチ何だっけ? 一瞬でわかるようにGitブランチに説明文を付けて、git branch で一覧表示する

Last updated at Posted at 2025-11-19

Gitブランチに説明文を付けて、git br で一覧表示する

ブランチが増えてくると「このブランチ何だっけ?」となりがちです。
Git標準の「ブランチ説明文」機能と、簡単なエイリアス設定だけで、説明付きのブランチ一覧を出せるようにします。


1. ブランチに説明文を付ける

任意のブランチに対して、次のコマンドで説明文を設定できます。

git branch --edit-description # developエディタが開くので、例のように説明を書いて保存します。

開発用メインブランチ。staging へのマージ元。同様に、他のブランチにも説明を付けられます。

git branch --edit-description feature/1234-fix-bug
git branch --edit-description feature/5678-new-api---

エイリアスにしておくと楽です

git config --global alias.bd 'branch --edit-description'
# カレントブランチにコメント
git bd

# 特定のブランチにコメント
git bd feature/xxx

のように使えます。

2. git br エイリアスを設定する

一度だけ、次のコマンドをターミナルで実行します(グローバル設定に登録されます)。

git config --global alias.br '!f(){ current=$(git symbolic-ref --short HEAD 2>/dev/null || echo ""); green=$(tput setaf 2); reset=$(tput sgr0); git for-each-ref --format="%(refname:short)" refs/heads | while read -r branch; do mark=" "; color=""; end=""; [ "$branch" = "$current" ] && mark="*" && color="$green" && end="$reset"; desc=$(git config --get "branch.$branch.description"); printf "%s %s%-30s %s%s\n" "$mark" "$color" "$branch" "$desc" "$end"; done; }; f'

正常にエイリアスに設定できていれば上記コマンドが表示されるはずです。

git config --global --get alias.br

3. git br を使ってみる

リポジトリ内で次を実行します。
git br説明文を設定していれば、次のように表示されます。

% git br
* develop                      開発用メインブランチ。staging へのマージ元。
  feature/1234-fix-bug         バグ1234の修正対応
  feature/5678-new-api         新APIエンドポイント追加-
  • 先頭の * : 現在チェックアウトしているブランチ
  • 左側 : ブランチ名
  • 右側 : git branch --edit-description で付けた説明文

4. うまくいかないときの簡単チェック

エイリアスが入っているか

git config --global --get alias.br

何も出なければ、もう一度エイリアス設定コマンドを実行します。


説明文が付いているか
ブランチ名一度説明文を保存してから、再度 git br を試してみてください。

git branch --edit-description 

これだけで、ブランチの意味を「一覧で思い出せる」ようになるので、ぜひ取り入れてみてください。

8
6
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
8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?