40

I create a new git repository with the help of bitbucket called confusionmatrix. Now, I'm trying in another git repository (called workspace) add the confusionmatrix repository as submodule like this:

git submodule add https://....@bitbucket.org/..../confusionmatrix.git

But I'm getting the following error:

'confusionmatrix' does not have a commit checked out

I already made this with other git repositories to the same repository "workspace" and worked well.

What I'm doing wrong?

Ricardo Rocha
  • 11,592
  • 13
  • 62
  • 108

8 Answers8

76

As an FYI, the same message is shown if by accident you already have a .git folder in any of the subfolder under the folder you are trying to add. If that's the case, then delete the git subfolder and if any .vs file is there, delete that too. That was my case and I had the same error message.

Muniro
  • 1,619
  • 2
  • 10
  • 9
  • 4
    Hey Thanks ! Removing the internal git folder worked for me. – Shagun Pruthi Oct 27 '20 at 13:32
  • 1
    This may happen as result of a previously failed `git submodule add` (in my case, the submodule was not populated yet and had not any commit). Then just delete the entire directory of the submodule (including the `.git` file). – Adrian W Nov 20 '20 at 21:31
  • Following this, I ended up with this error message "A git directory for '[submodule-name]' is found locally with remote(s):" [...] If you want to reuse this use the --force option. I Had to use `rm -rf .git/modules/[submodule-name]` credits to https://stackoverflow.com/a/38420557/2832282 – Cyril Duchon-Doris Dec 06 '21 at 10:09
24
  1. Find leftover .git folder in some sub directories (the directory is shown in the error msg!)
find ./ -name '.git'
  1. Delete it (make sure to have the right folder!!!)
rm -r yourfolder/.git/
  1. try again
gies0r
  • 3,745
  • 1
  • 33
  • 40
23

If you just created an empty Git repository on BitBucket, try and make sure to make at least one commit (or push one commit) to it.

Do that before referencing that repository as a submodule in your second local repository.

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
6

I had another .git folder in subdirectory, I did pull from repository before initializing it, after deleting that repository, git add . worked

atazmin
  • 3,144
  • 1
  • 22
  • 12
  • 2
    I had the same issue. My framework (Nest.js) automatically created a `.git` folder in the project's subdirectory. I had to remove before I could commit the subdirectory. – Elias Strehle May 26 '21 at 10:34
3

This worked for me

In my case subfolder is containing .git folder.

Check if any subfolder contains '.git' folder. Delete that ".git" folder and it will work.

OR

In git-shell Run

rm -rf .git
GAURAV MOKASHI
  • 1,337
  • 2
  • 12
  • 16
2
git commit -m "if you have something you want to Keep comment"

delete branch manually with all files on your disc

git clone https://WhereMyOriginIs" MyLocalFolderName
Maximilian Ast
  • 3,240
  • 12
  • 39
  • 46
1

Please check your subfolder (others). which is also contain the .git directory so remove (delete) this folder. after that again {git add -> git commit -m -> git push origin} those commands are executed then your problem has been solved.

thank you.

1

It occurs whenever by mistake you keep your init folder where it points out. In my case, I kept it in the Gallery folder by mistake and again initialized it in the same project during adding all the projects it showed this error.  does not have a commit checked out

Naffy Kausar
  • 81
  • 1
  • 2
  • 9