68

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
  • 14,612
  • 20
  • 74
  • 130

14 Answers14

107

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,989
  • 3
  • 11
  • 9
  • 7
    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
  • +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. – Wipqozn Jun 24 '23 at 18:39
  • In my case i had a .git folder under venv. I removed it and it works. – luki Jul 18 '23 at 12:15
54
  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
  • 4,723
  • 4
  • 39
  • 50
  • 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 @giesOr – Sumit Jul 18 '23 at 11:23
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,262,500
  • 529
  • 4,410
  • 5,250
10

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
GAURAV MOKASHI
  • 1,906
  • 2
  • 14
  • 17
8

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

atazmin
  • 4,757
  • 1
  • 32
  • 23
  • 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

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

Vipul Pandey
  • 1,507
  • 11
  • 20
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,369
  • 12
  • 36
  • 47
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
  • 91
  • 2
  • 2
  • 9
1
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.

Iker Solozabal
  • 1,232
  • 11
  • 16
0

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

jgu7man
  • 326
  • 1
  • 3
  • 10
-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...

lodey
  • 174
  • 2
  • 8
-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 .......

Niranjanadas M
  • 153
  • 2
  • 10
-2

I'm trying to learn about submodules, and I am currently having just this problem.

What I don't understand is the following: isn't a submodule supposed to have a .git file? (but maybe not a folder (i.e. directory)

In the example below, the .git file in the submodule directory has a relative path back to the .git/modules directory in the parent directory (what the example calls the superproject.

In the example worked out in Version Control with Git (3rd edition, pp 355-356) the author does the following

% mkdir superproject
% cd superproject
% git init -b main
% echo "superproject" > sp-readme.md
% git add .
% git commit -m "add sp-readme.md"

and then, adds the submodule

% git submodule add git@github.com:ppremk/example-submodule-updated.git

Cloning into '<...>/superproject3/example-submodule-updated'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (5/5), done.
Receiving objects: 100% (6/6), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0

% git commit -m "added submodule"
[main 6683546] added submodule
2 files changed, 4 insertions(+)
create mode 100644 .gitmodules
create mode 160000 example-submodule-updated

% git status
On branch main
nothing to commit, working tree clean
 
% ll example-submodule-updated
total 24
drwxr-xr-x@ 5 whdaffer  703763885  160 Jan 31 18:14 ./
drwxr-xr-x@ 6 whdaffer  703763885  192 Jan 31 18:14 ../
-rw-r--r--@ 1 whdaffer  703763885   50 Jan 31 18:14 .git
-rw-r--r--@ 1 whdaffer  703763885   62 Jan 31 18:14 README.md
-rw-r--r--@ 1 whdaffer  703763885   59 Jan 31 18:14 new-file.md
 
% file example-submodule-updated/.git
example-submodule-updated/.git: ASCII text
 
% cat example-submodule-updated/.git
gitdir: ../.git/modules/example-submodule-updated

Looking at the directory that the submodule .git file mentions, it looks like a normal .git directory for a stand-alone repo.

% cd example-submodule-updated
% ll ../.git/modules/example-submodule-updated


total 40
drwxr-xr-x@ 12 whdaffer  703763885  384 Jan 31 18:15 ./         
drwxr-xr-x@  3 whdaffer  703763885   96 Jan 31 18:14 ../        
-rw-r--r--@  1 whdaffer  703763885   21 Jan 31 18:14 HEAD       
-rw-r--r--@  1 whdaffer  703763885  364 Jan 31 18:14 config     
-rw-r--r--@  1 whdaffer  703763885   73 Jan 31 18:14 description    
drwxr-xr-x@ 15 whdaffer  703763885  480 Jan 31 18:14 hooks/     
-rw-r--r--@  1 whdaffer  703763885  217 Jan 31 18:15 index      
drwxr-xr-x@  3 whdaffer  703763885   96 Jan 31 18:14 info/      
drwxr-xr-x@  4 whdaffer  703763885  128 Jan 31 18:14 logs/      
drwxr-xr-x@  4 whdaffer  703763885  128 Jan 31 18:14 objects/       
-rw-r--r--@  1 whdaffer  703763885  112 Jan 31 18:14 packed-refs    
drwxr-xr-x@  5 whdaffer  703763885  160 Jan 31 18:14 refs/          

So, my question to those who suggest removing the .git file in the submodule directory: doesn't that destroy the characteristic of the subdirectory as a submodule and just turn it into a regular subdirectory of the parent? Meaning that it no longer tracks the changes that the submodule comes from.

Keep in mind, I'm just learning this part of git, and having problems to boot, so I could be asking a stupid question.

If so, please advise.

whdaffer
  • 29
  • 4
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/33751461) – Inigo Feb 07 '23 at 08:57