1

I had a project form a remote repo that was a submodule in my project. I forked that remote project, removed the old submodule, and then tried to add my forked copy. This doesn't work.

What I did was:

 git submodule deinit path/to/sub
 git rm /path/to/sub
 git push origin mybranch

then

 git submodule add url_of_forked_project_in_my_repo path/to/sub

I get some weird message about the repo being local, that I should use --force or --name, and the end effect of trying any of those is that my local fork does not update with any changes I make, and the references remain to the old submodule HEAD.

The message is:

A git directory for 'path/to/sub' is found locally with remote(s): origin git://github.com/SomeoneElse/project If you want to reuse this local git directory instead of cloning again from git@github.com:myrepo/project.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.

If I use the --force option, I'm able to get the submodule, but references don't seem to update and changes I make in my the submodule in my main project don't propagate anywhere: is that what's meant by local?

At any rate, I just want a normal, run of the mill submodule, where updating in my main project's copy creates changes in references and so on.

Any help would be appreciated.

MrSilverSnorkel
  • 499
  • 1
  • 5
  • 17
  • Check out this: http://stackoverflow.com/questions/913701/changing-remote-repository-for-a-git-submodule Perhaps you can fix the problem by editing the .gitmodules file in the root of your repository manually. – jpe Nov 25 '14 at 20:28
  • That is indeed what I ended up doing. Good to know I'm not the only one to have resorted to such means! – MrSilverSnorkel Nov 25 '14 at 20:29
  • Leaving unanswered in case someone has a better solution. As mentioned above, I edited the .gitmodules file to point to the proper repo. When fetching, others on my team had to `git submodule sync` to make everything jive. – MrSilverSnorkel Nov 25 '14 at 20:31

1 Answers1

1

You're not alone. I troubleshooted the problem by following this answer. Do keep in mind deleting not only the corresponding snippet in the .gitmodule file is necessary but also the subdirectory under .git/modules.

If you're versioning your repo, like dotfile as me, using links in a folder, you'll be nevigated to the related directory for the module which should be deleted.

Lerner Zhang
  • 6,184
  • 2
  • 49
  • 66