How to fix “warning: ignoring ref with broken name” in git?

I’m working on OSX. In a particular repo, whenever I tab to autocomplete after typing a git command:

$ git diff [clicks tab...]

I now see a huge number of warnings:

  • git remotes of same working directory are different (or at least it seems like it)
  • Meaning of Git checkout double dashes
  • JGit : How to get Branch when traversing repos
  • Use gruntjs as precommit hook
  • Can I use Git to apply update patches to customized software?
  • Can I convert my TODO to a git bug?
  • warning: ignoring ref with broken name refs/Icon
    warning: ignoring ref with broken name refs/heads/Icon
    warning: ignoring ref with broken name refs/remotes/Icon
    warning: ignoring ref with broken name refs/remotes/origin/Icon
    warning: ignoring ref with broken name refs/tags/Icon
    

    It’s really annoying, and it means that I can’t see the filenames I want to see.

    How can I remove or suppress these warnings?

    I have an entry for Icon? in my gitignore file. There is an Icon? file in the local directory.

    For all the trigger-happy people about to click “duplicate”: I’ve searched for other answers, I found this but I’m not sure how it relates to my situation. It may be that the underlying cause is the same, but it would benefit me and others to have an explanation of how to fix this problem.

  • Git merging release branches conflicts because of minor version changes
  • How do I prevent capistrano from overwriting files uploaded by users in their own folders?
  • Dropping a commit in git rebase -i does not reduce the size of .git folder
  • Use a non-newest git checkout in a buildout-based Plone site
  • Second develop branch in git
  • Jenkins Git plugin and Refspecs
  • One Solution collect form web for “How to fix “warning: ignoring ref with broken name” in git?”

    The Icon\r file is created by Mac OS when you change a folder’s icon.

    How can I remove or suppress these warnings?

    You need to delete the offending files themselves.

    I have an entry for Icon? in my gitignore file.

    That makes no difference. A .gitignore works on the working directory; these files are inside the repository folder where Git stores its metadata. .gitignore does not apply there. Git is mistaking them as branch names.

    To fix this problem, you may be able to remove the custom icon you gave your folder(s). But if not, you will need to remove the files from beneath the .git folder. You can do this in Finder (after turning on “Show Hidden Files”) or from the command line:

    rm .git/refs/Icon?
    

    Make sure to backup your repository before attempting this as changing things in the .git folder can corrupt your repository.

    Git Baby is a git and github fan, let's start git clone.