2

When running the git init command in a completely new and empty directory, I get this error message:

Reinitialized existing Git repository in /<just path stuff>/gittests/completelyEmptyDirectory/.git/

What is going on here? The only commands being run are mkdir completelyEmptyDirectory, going into that directory, and then running git init.

Duskendale
  • 142
  • 4
  • 13
  • Do ls -al in your "completelyEmptyDirectory" and see if it shows you a .git directory. If so, then this is already a git repo. – Bagels1b Oct 07 '22 at 19:08
  • Yes I have confirmed and double checked this as it is the most common issue people have. The directory being created is completely empty and it's completely empty when running the init command. – Duskendale Oct 07 '22 at 19:19
  • Is this newly-created directory stored in some kind of cloud-synchronized storage, e.g., Dropbox or iCloud? If so, it's almost certainly being populated with a `.git` by said cloud-storage facility, for reasons known only to the cloud-storage fans. – torek Oct 08 '22 at 00:40
  • No, it's just on the `/Users/Duskendale` directory, nothing special about it. I have also tried in other directories and it's all the same. – Duskendale Oct 09 '22 at 02:34
  • I haven't been able to re-create this. Is gittests a git repo itself? Maybe something weird going on with creating a repo within a repo? I'm not overly familiar with git debug but this [post](https://stackoverflow.com/questions/6178401/how-can-i-debug-git-git-shell-related-problems) has some debug you can turn on. Maybe that will give you some insight. – Bagels1b Oct 09 '22 at 04:36

2 Answers2

2

That is not an error message but the message produced by git init when it is executed into an existing repository. You probably executed git init twice in that directory and this is the message produced on the second run.

The documentation of git init explains:

Running git init in an existing repository is safe. It will not overwrite things that are already there.

axiac
  • 68,258
  • 9
  • 99
  • 134
  • Yes that is correct, I misspoke, it is not an error message, simply a message. However with that being said I know for a fact that I am not executing it in an existing repo. I just `rm -rf`ed the previous directory, made a new one, and ran git init and it's the same thing. I also have confirmed and know for a fact that the directory I'm doing this is is not itself a git repo. Therefore it unfortunately cannot be a result of what you've described. – Duskendale Oct 07 '22 at 19:12
  • This is the only way I could get that message. I ran `git init` in a directory that already contains a Git repository. – axiac Oct 07 '22 at 19:39
  • Yes this is why I am incredibly frustrated, there is no reason this should be happening. It is preventing me from running other commands I need to run in a script. – Duskendale Oct 07 '22 at 20:26
-1

After investigating further the reason this was happening is because in my .gitconfig the [init] section was pointing to my .git_templates folder. The templates folder contains only one file called HEAD that had this:

ref: refs/heads/main

Not sure exactly why this was causing the error above.

Replacing that line with:

defaultBranch = main

resolved the issue. Still would like to figure out why the [init] was set to point to the .git_templates in the first place.

Duskendale
  • 142
  • 4
  • 13
  • Changing this completely broke my ability to init a new git repo properly. The command ran, but the default branch was broken. I had to revert this change. Using `git version 2.40.1`. – spkane May 19 '23 at 18:57