@kyanny's blog

My thoughts, my life. Views/opinions are my own.

Git: リモートで削除済みのローカルブランチを消す

リモートで削除済みのブランチを調べるには git branch -v オプションを使う。

[gone] とマークされているのが削除されているブランチ。それを git branch -d なり -Dなりで削除すれば良い。

削除済みリモートブランチを追跡しているローカルブランチを1発で全削除するコマンド - Technology Engineering

(ちょっと [gone] を手元でうまく再現できないので、上記ブログから例を拝借)

$ git branch -v
* develop           fef1cdd Merge pull request #30 from abcdef/fix/bazbarfoo
  feature/foo       e57408f [gone] Fix deploy
  feature/bar       a9b73ad [gone] Upload image
  feature/baz       b833113 [gone] Fix test
  feature/foobar    703e2ad [gone] Add foobar.c
  feature/foobaz    1587581 [gone] Fix foobaz.rb
  feature/barfoo    37265cb [gone] Add barfoo.php
  feature/barbaz    3c121ca [gone] Fix barbaz.py
  feature/bazfoo    cb69767 [gone] Add bazfoo.go
  feature/bazbar    bb8575f [gone] Fix bazbar.pl
  feature/foobarbaz 66d2807 [gone] Fix README.md
  fix/foobazbar     84a781e [gone] Add gitignore
  fix/bazfoobar     cd36a6b [gone] Fix ci
  master            0a41ce8 Merge pull request #20 from abcdef/develop

[gone] とは何か、については git for-each-ref のドキュメントで触れられている。

Git - git-for-each-ref Documentation

upstream

The name of a local ref which can be considered “upstream” from the displayed ref. Respects :short, :lstrip and :rstrip in the same way as refname above. Additionally respects :track to show "[ahead N, behind M]" and :trackshort to show the terse version: ">" (ahead), "<" (behind), "<>" (ahead and behind), or "=" (in sync). :track also prints "[gone]" whenever unknown upstream ref is encountered. Append :track,nobracket to show tracking information without brackets (i.e "ahead N, behind M").