66
35

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

gitで warning: ignoring broken ref refs/remotes/origin/HEAD ってエラーが出た時の対処法

Last updated at Posted at 2016-08-25

最近はずっとsource treeで作業していたんですが、ある日 push -f する必要があってターミナルから実行しようとしてbranchをtabで補完しようとしたら、、、

warning: ignoring broken ref refs/remotes/origin/HEAD

なんて出てきて補完できない状態に😨

いろいろググってたら git gc がどうのこうのとか出てきたので実行しようとしたら

% git gc
(git)-[{yourDefaultBranch}]
fatal: bad object refs/remotes/origin/HEAD
error: failed to run repack

まじか。。。

もう1回上記エラーでググる。

git pull origin master で直るでみたいな記事を発見。

% git pull origin {yourDefaultBranch}                                                                                                                                                                                                                (git)-[{yourDefaultBranch}]
From github.com:Hoge/fuga
 * branch            {yourDefaultBranch} -> FETCH_HEAD
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
error: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log.
Automatic cleanup will not be performed until the file is removed.

fatal: bad object refs/remotes/origin/HEAD
error: failed to run repack

Updating 2d391b0..df04d0f
Fast-forward
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
error: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log.
Automatic cleanup will not be performed until the file is removed.

fatal: bad object refs/remotes/origin/HEAD
error: failed to run repack

直らない😨😨😨

解決方法

詰んだ。。。と思いましたが更に対処法を探してると以下の記事を発見!!
https://www.netroby.com/view/3864
記事通り以下のコマンドを実行

git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/{yourDefaultBranch}
git fetch --prune
git gc

僕の場合はこれで直りました!
よかったよかった!

参考URL

Fix bad object refs/remotes/origin/HEAD while execute git gc
https://www.netroby.com/view/3864

66
35
1

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
66
35

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?