2

On Windows Git has problems with refs differing only in the case:

$ git branch foo
$ git branch FOO
fatal: A branch named 'FOO' already exists.

$ git branch dir/foo
$ git branch DIR/bar
$ git branch --list
* develop
  foo
  dir/bar
  dir/foo

That can be explained by Git using the file system to store the refs as a file foo and bar inside the directory <repository>/.git/refs/heads/dir.

$ git branch --delete dir/bar
$ git branch --delete dir/foo
$ git branch --list
* develop
  foo

Older Git versions seem to have left some empty directories in <repository>/.git/refs where newer Git versions remove them.

Is it safe to remove empty directories in <repository>/.git/refs manually?

Thomas S.
  • 5,804
  • 5
  • 37
  • 72

1 Answers1

2

Is it safe to remove empty directories in <repository>/.git/refs manually?

Yes, if there is nothing else running. Git will re-create them if needed.

(If a Git command is running, it may decide that the directory exists and does not need to be created, and then you remove the directory, and then the Git command tries to use a file within the directory you just removed.)

Note that if you run git pack-refs --all, the existing refs will be combined into a single file containing the packed references. This will allow you to create new references that differ only in case—but don't do it, because when Git goes to update the references, it will stumble over the case-folding issue in your file system.

(The cure for this is for Git to stop using files in the file system to hold reference values. I believe this will happen someday, I just do not know when.)

torek
  • 448,244
  • 59
  • 642
  • 775