git submodule add error: does not have a commit checked out

Viewed 157173

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?

8 Answers

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.

  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

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.

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

In my case subfolder is containing .git folder.

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

OR another way is

In git-shell Run

rm -rf .git
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

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.

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

Related