LoginSignup
492
415

More than 5 years have passed since last update.

リモートで消されたブランチが手元で残ってしまう件を解消する

Posted at

よそからcloneしてきたリポジトリでは、remotes/origin/xxxという名前でoriginのブランチが参照される。

$ git branch -a
* master
  remotes/origin/hoge
  remotes/origin/fuga

だが、他の人がhogeブランチを削除してoriginにpushしても、既にそのブランチが手元にある人のローカルリポジトリからは普通にpullしても消えてくれない。

そういった既にリモートで削除されているブランチを消したい場合は、以下のどちらかの操作を実行すればちゃんと消えてくれる。

git fetchもしくはgit pullにpruneオプションをつける

--pruneオプションをつけると、fetchやpullする際に自動的にリモートで削除されているリモートブランチを削除してくれる。

$ git fetch --prune
 x [deleted]         (none)     -> origin/hoge

git remote pruneを実行する

$ git remote prune origin
 x [deleted]         (none)     -> origin/hoge
492
415
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
492
415