0

So, I have a folder called my-folder which has been initialised as a git repository. Inside this folder, I have another folder called my-project (it is an angular project). As you may know, an angular project has several files and folders in it.

I am trying to git add all of the contents of my-project. To do this, I use the following commands in git bash:

git add my-project
git add my-project/* 

The second command is supposed to git add all of the contents of my-project (according to How to push a new folder (containing other folders and files) to an existing git repo?).

However, the second command gives me an error. It says

fatal: Pathspec 'my-project/README.md' is in submodule 'my-project'

I am relatively new to git. Could someone explain what this error means and how I could resolve it?

Thanks

torek
  • 448,244
  • 59
  • 642
  • 775
Diamoniner12345
  • 414
  • 2
  • 10
  • 2
    Your subfolder is itself a git repository (submodule), so you want that or is it a mistake? – Gaël J Aug 17 '21 at 20:36
  • 1
    As @GaëlJ says, you're getting a submodule. Git literally cannot store another Git repository inside a Git repository, so it just won't. I closed this as a duplicate of a question about submodules, but let me know if you want it re-opened. – torek Aug 18 '21 at 00:49
  • @torek I actually had deleted the .git folder in my-project. Though I still can't understand why I am getting this error message? – Diamoniner12345 Aug 18 '21 at 18:08
  • Once the superproject thinks it's a superproject with `my-project` as a submodule, any attempt to add any *files* within the submodule will produce that error. You can run `git rm --cached my-project` to remove the gitlink that tells your Git software, running on your top-level repo (the "superproject" until the gitlink is gone), that it's acting as a superproject for submodule `my-project`. If you've done a `git submodule add` you should do more to remove this, but if you've merely done a `git add` that created the gitlink, all you need to do is remove the gitlink. – torek Aug 19 '21 at 00:10
  • Once the gitlink itself is gone, Git won't think of the current repository as a superproject in which `my-project` is itself a submodule. *Now* a `git add my-project/some-file` will get past the "it is a submodule" error to the point of looking inside `my-project` for `some-file`. If that exists as a file (and there's no `.git` causing in `my-project` either), *now* Git will add `my-project/some-file` as a file to its index/staging-area, ready for the next commit. – torek Aug 19 '21 at 00:12

1 Answers1

1

It looks like you have already staged changes in my-project dir with your first command. So git is complaining when you are trying to add with second command.

Below should work if you have not staged anything.

If you have staged changes, try git reset and then below command

If still failing, try git rm --cached directory and git add my-project

git add my-project
git commit -m "Commit changes in my-project"
git push origin master