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 clear remote repository
  • PHPStorm and other JetBrains IDE's: how to change default git colors?
  • How to list all Git tags?
  • Reverting a series of pushed merges and commits in Git (without rewriting history)
  • Merging multiple Git repositories with tags
  • JGitFlow maven plugin doesn't push release branch to remote
  • 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.

  • In GIT, what is the best way for a project to mix old and new versions of sub-components?
  • Upgrading git from the source repository in Ubuntu
  • Git push complaining about non-fast-forward, even though remote has been pulled
  • How to do git merge/pull correctly: You have not concluded your merge (MERGE_HEAD exists)
  • Git merge conflict since I deleted a file
  • Git “missing” commit
  • 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.