とあるプロジェクトで、気まぐれにブランチ一覧を確認したら消したはずのブランチが残って見えた。
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/old_branch
消し忘れかな?と思って消そうとしたけど、やっぱりリモートリポジトリからは消えてるみたい。
$ git push origin :old_branch
error: unable to delete 'old_branch': remote ref does not exist
error: failed to push some refs to 'https://github.com/xxx/yyy'
調べてみるとリモートリポジトリ上で直接ブランチを消す等するとこんな状態になるみたい。
直すにはgit remote prune
コマンドを使うと良い。
$ git remote prune origin
Pruning origin
URL: https://github.com/xxx/yyy
* [pruned] origin/old_branch
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
おお、消えた!
pruneって単語は聞き慣れないけどミキプr「余計な枝を切り払う」という意味があるそうな。まさにイメージ通りですね・・・勉強になりました。