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

5
  • 2
    Your subfolder is itself a git repository (submodule), so you want that or is it a mistake? Commented Aug 17, 2021 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. Commented Aug 18, 2021 at 0: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? Commented Aug 18, 2021 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. Commented Aug 19, 2021 at 0: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. Commented Aug 19, 2021 at 0:12

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.