10

I'm trying to add a git submodule to my project, specifically ShareKit. My project is a git repo, and when I try to type

git submodule add git://github.com/ShareKit/ShareKit.git Submodules/ShareKit 

into Terminal I got an error saying that the submodule already existed. I guess I added it a while ago to this project, and ended up not using it and improperly deleting it from the project directory (just deleting the submodule folder, most likely). So I try and do

git rm --cached Submodules/ShareKit 

according to How do I remove a submodule?, and now when I try and add the submodule again with the first bit of code I get this:

A git directory for 'Submodules/ShareKit' is found locally with remote(s): origin git://github.com/ShareKit/ShareKit.git If you want to reuse this local git directory instead of cloning again from git://github.com/ShareKit/ShareKit.git use the '--force' option. If the local git directory is not the correct repo or you are unsure what this means choose another name with the '--name' option. 

and I'm not really sure what to do. I'm fairly new to git, and I need to get this in my project - is there any way to just wipe everything git related off of the project and start from scratch? I'd just do it with a new project but it's already pretty much complete aside from this and it would be hugely time-consuming to start from scratch and copy everything over. I have ShareKit working in a test app, installed properly, is there any reason I can't just copy all of the ShareKit files from that folder into the one I need them in?

Edit: I have tried

git submodule deinit Submodules/ShareKit 

which gives me this error:

error: pathspec 'Submodules/ShareKit' did not match any file(s) known to git. Did you forget to 'git add'? 

It seems like it's stuck in some sort of weird state where it's both insisting that the submodule does and doesn't exist simultaneously. I'm doing this with Terminal to add the submodule to an Xcode project, just to clarify.

3
  • 3
    Have you removed .git/modules/Submodules/ShareKit? Commented Nov 11, 2013 at 20:59
  • I'm not sure how to do that, like I said I'm pretty new to git. Commented Nov 11, 2013 at 21:27
  • try rm, it's a unix command. If you're using windows, use windows explorer to delete that folder. Commented Nov 11, 2013 at 21:56

2 Answers 2

19

Try the following to force git to re-add the submodule:

git submodule add --force git://github.com/ShareKit/ShareKit.git Submodules/ShareKit 

Note the --force after add.

If you'd want to remove version handling altogether, simply remove .git and .gitmodules.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried doing that and it gave me "'Submodules/ShareKit' already exists in the index" again, which is what I got initially before trying the rm command. I'd scorch the earth by removing .git and .gitmodules but those don't show up in Finder in my project folder, even if I say "git init" to reinit the project as a git repo.
.git and .gitmodules are hidden files. Unless you tell Finder to show them, they'll remain hidden. You can remove them using the terminal with $ rm -r .git .gitmodules
I ended up running "git rm Submodules/ShareKit" again, and then did what you said above, and that time it worked. I'm not really sure what weird arcane order I ended up doing things in to make it happy, but it's in the project now and that's all I need. Thanks a ton!
I had hidden files and folders set to display though, which is the weird thing. Maybe I entered the command improperly and didn't realize it, I'm not sure.
5

iveqy's comment did the trick for me, posting it as an answer so that it is more visible.

Simply delete the following folder (adjust with your submodule's path):

 .git/modules/Submodules/ShareKit 

You can delete it with rm path -rf under unix, or to be safe just move it to /tmp (it should be erased on next boot, but gives you time to change your mind if you deleted the wrong folder):

 mv .git/modules/Submodules/ShareKit /tmp/ShareKit-deleted 

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.