LoginSignup
1
2

More than 5 years have passed since last update.

gitのエラー(Your branch is ahead of 'origin/hotfix/hogehoge' by 5 commits.)

Last updated at Posted at 2018-06-10

エラー内容

$ git status
On branch fix/hogehoge
Your branch is ahead of 'origin/hotfix/hogehoge' by 5 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

なぜか現在のブランチfix/hogehogeが、hotfix/hogehoge(削除済みのブランチ)を追跡していた。
なのでhotfix/hogehogeから5つ分コミットが進んでしまってますよ〜大丈夫ですか?という指摘をされた。
この状態でのpull、push等は何も問題はないのだが、なんだか気持ち悪いので対処したい。

対処法

現在の状況を確認

$ git branch -a
* fix/hogehoge
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/hotfix/hogehoge //ローカル、リモートともに削除済みのブランチを追跡中
  remotes/origin/fix/hogehoge
  remotes/origin/master

allオプションを付けて作業ブランチ、追跡ブランチを確認。

追跡ブランチにローカル、リモートともに削除済みのブランチ(hotfix/hogehoge)が残っており、現在のブランチ(fix/hogehoge)はそれと紐付いていた。

(今回はpush→pullもしていたため、remotes/origin/fix/hogehogeも同時に存在している)

追跡ブランチを削除

$ git fetch --prune
From github.com:<リポジトリ名>
 - [deleted]         (none)     -> origin/hotfix/hogehoge

ブランチの削除はリモートとローカルの間で反映されないため、pruneオプションを付けてgit fetch --pruneを行う。

これでリモートブランチの削除をローカルに反映する事ができる。

参考:https://qiita.com/yuichielectric/items/84cd61915a1236f19221

$ git branch -a
* fix/hogehoge
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/fix/hogehoge
  remotes/origin/master

//remotes/origin/hotfix/hogehogeがなくなっている

これでリモートで削除済みのhotfix/hogehoge(リモートブランチ)に対するorigin/hotfix/hogehoge(追跡ブランチ)が削除された。

追跡を解除

これで解決するかと思ったら、追跡ブランチがなくなっても紐付きは解除されないらしい。

$ git status
On branch fix/hogehoge
Your branch is based on 'origin/hotfix/hogehoge', but the upstream is gone.
  (use "git branch --unset-upstream" to fixup)

nothing to commit, working tree clean

エラー文に従い、git branch --unset-upstreamを行う。

$ git branch --unset-upstream
$ git status
On branch fix/set-tokyo-timezone
nothing to commit, working tree clean

これで解除されので、次にgit pushした時にremotes/origin/fix/hogehogeが追跡ブランチになるはず。(恐らく...)

ひとまず解決!

参考

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