1
0

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-12-09

はじめに

GitHub 上でブランチを削除したのに、git branch をすると ローカルにまだブランチが残っているという経験はありませんか?

この記事では、その理由と根本的な解決方法を Mermaid でわかりやすく説明します。

1. 現象の例

GitHub 上で次のブランチを削除したとします。

feature/xx
feature/yy
feature/zz

しかしローカルではまだ残っています。

$ git branch
  feature/xx
  feature/yy
  feature/zz
* main

2. 図解:Git のブランチは 2 種類ある

Git には以下の 2 種類のブランチがあります。

種類 説明
ローカルブランチ feature/foo あなたの PC に実体として存在
リモート追跡ブランチ origin/feature/foo GitHub の状態を記録したキャッシュ

ローカル・origin・GitHub の関係

3. git fetch --prune で不要な追跡ブランチを削除

GitHub で削除されたブランチは、以下でローカルの追跡ブランチを消せます。

$ git fetch --prune
From github.com:xxxx/xxxx
 - [deleted]         (none) -> origin/feature/xx
 - [deleted]         (none) -> origin/feature/yy
 - [deleted]         (none) -> origin/feature/zz

prune の図解

4. それでもローカルに残る理由

理由はとてもシンプルで、

git fetch --pruneorigin/xxx しか消さず、ローカルブランチ feature/xxx は消さない

からです。

Mermaid 図

5. 解決方法:ローカルブランチを削除する

不要なブランチは手動で削除します。

$ git branch -d feature/xx
$ git branch -d feature/yy
$ git branch -d feature/zz

未マージでどうしても消したい場合は強制削除:

$ git branch -D feature/ww

6. 自動 prune を有効にする(おすすめ)

$ git config --global fetch.prune true

これで今後、git fetchgit pull のたびに自動で不要な追跡ブランチが整理されます。

7. 全体の流れ

まとめ

状況 原因 解決
リモートで削除したのに残る ローカルブランチが残っている git branch -d
origin/xxx が残る prune をしていない git fetch --prune
今後自動で prune したい 設定がオフ git config --global fetch.prune true

Git は便利ですが、ブランチ管理は慣れるまで混乱しがちです。
この記事が理解の助けになれば幸いです。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?