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

13

77

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://[email protected]/..../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?

Captivity answered 27/6, 2019 at 23:51 Comment(0)
S
24

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.

Sev answered 28/6, 2019 at 4:52 Comment(0)
Z
119

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.

Zinnes answered 3/8, 2020 at 20:54 Comment(5)
Hey Thanks ! Removing the internal git folder worked for me.Lipsey
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).Nullification
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://mcmap.net/q/92693/-git-submodule-add-quot-a-git-directory-is-found-locally-quot-issueBrigitte
+1 This was the error for me as well. Visual Studio automatically create a .git folder, even though it was already part of a repo. This answer is what made me check for the folder.Rizika
In my case i had a .git folder under venv. I removed it and it works.Bahamas
A
63
  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
Ankus answered 12/4, 2021 at 23:31 Comment(1)
On the submodule, if you initialize git then you may have this problem. I accidentally had done the same, I followed the above steps and it worked. Thanks @giesOrNaamann
S
24

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.

Sev answered 28/6, 2019 at 4:52 Comment(0)
U
13

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
Uxorial answered 11/3, 2021 at 18:36 Comment(1)
Run "rm -rf .git" in git-shell, works like a charm for meTopheavy
N
8

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

Nejd answered 17/2, 2021 at 16:57 Comment(1)
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.Lekishalela
S
3

its due to a inner git project available inside your submodules. try searching for .git folder and remove that.

Silage answered 8/11, 2022 at 5:38 Comment(0)
S
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
Singletree answered 2/9, 2019 at 7:49 Comment(0)
V
2
error: '[route]' does not have a commit checked out
fatal: adding files failed

This error may be generated because a .git file is found on the route than can not be add

If you navigate to the [route] and execute git status and recieve the next error

fatal: detected dubious ownership in repository at '[route]'

Is because you have another repository inside your main repository.

Velocipede answered 8/3, 2023 at 19:39 Comment(0)
P
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.

Peterkin answered 31/1, 2022 at 18:21 Comment(0)
H
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

Hernia answered 22/2, 2022 at 6:17 Comment(0)
E
1

I found a simple solution when this occurs on rebase action

git rm --cached <submodule/path>
git add .
git rebase --continue

I hope somebody found this helpful

Epidote answered 6/6, 2023 at 5:34 Comment(0)
S
-1

I also had same issue and this is what i did

cd folder name
rm -rf git
then cd .. back to main folder
then git add .

it work, thank to all...

Spectacular answered 18/12, 2022 at 5:23 Comment(0)
L
-1

In My case what happened was, I accidentally added git init in one of the sub folders . So i just deleted those .gits from sub folders.

There should be only one .git file in your folder, there should not be any in any subfolders.

Removing them worked for me. and then Try again from beginning : 1. git init 2. git add -A .......

Larochelle answered 4/1, 2023 at 8:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.