LoginSignup
52
38

More than 5 years have passed since last update.

Gitのリモートブランチがローカルでゾンビ化した場合の対処法

Posted at

とあるプロジェクトで、気まぐれにブランチ一覧を確認したら消したはずのブランチが残って見えた。

$ 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「余計な枝を切り払う」という意味があるそうな。まさにイメージ通りですね・・・勉強になりました。

52
38
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
52
38