1

I'm trying to create a new repository and add two projects to it. One of the projects was already under Git source control so I copied the project and removed the .git folder and deleted the repository I had for it. When I add the projects to my repository the one that wasn't under source control gets added fine but the other one gets added as a submodule (green folder on GitHub).

I tried removing the submodule by doing git rm --cached on it, but it's still there and I can't add the files of the project to the repository.

8vius
  • 5,566
  • 12
  • 67
  • 133

2 Answers2

2
rm -rf path_to_submodule
rm -rf .git/path_to_submodule
rm .gitmodules
git commit -am "removing submodule"
git push

.gitmodules should be unexistent e .git/ shouldn't have refs from the submodule

check with:

git ls-files | grep submodule_name
find . | grep submodule_name

and finally:

git submodule add git@git.whatever.com.br:johndoe/johndoe_repo.git johndoe_branch/johndoe_repo --force

--force is optional if you have already the folder in your file system

Julio Marins
  • 7,929
  • 7
  • 40
  • 48
1

Have you tried with fresh checkouts yet ? There seems to be no git submodule remove, so you would have to manually edit the .gitmodules.

If you want to add module X (which is already under version control) to module Y (which is new) using checked-out copies:

  • Cd into X
  • Make sure it is a stand-alone module: there shouldn't be any .gitmodule (if there is, then it's more complicated).
  • Run git status to make sure you don't have any uncommitted changes.
  • Run git clean -xfd to get rid of anything that's in some .gitignore, like temporary build files, etc.
  • Remove the .git directory
  • Copy X into Y
  • Run git add X inside Y.

You could also do something like git clone path-to-Y in X followed by rm -rf Y/.git.

Martin Baulig
  • 2,839
  • 1
  • 13
  • 17
  • What if I have uncommited changes in this repository? Which is the case, because the previous GitHub repo was private and it expired, so I can't push the changes. – 8vius Oct 03 '12 at 14:58
  • Whatever the case, this solved my problem. Thank you, Martin. – 8vius Oct 03 '12 at 20:01
  • You could just commit locally, without pushing the changes. But of course, you could also copy while having uncommitted changes. Copying from a repo without uncommitted changes just makes it much easier to track history - you could include the revision in your commit message. – Martin Baulig Oct 03 '12 at 20:03
  • However, you must be very careful with `git clean -xfd` if you have any uncommitted changes - this command would delete any files that you added, but not add to the index yet. It's just the easiest way of quickly getting rid of all the temporary build files which are in your working tree, but not in the repository. – Martin Baulig Oct 03 '12 at 20:05