17

I have just realised I ran a 'git init' command from a sub-directory by mistake and then created a master repo at the root of my project.

This was a mistake, so I ran the 'rm -fr'

command (delete) on the nested directory '.git' not in the root of the project - thinking that this would solve my issue (how wrong I was)

The problem is now that when I push the project to GitHub the nested folder is greyed out as if it was ignored.

Is there any way to undo what I have done? or do I just have to start again? I'm new to this and was trying to complete a sample app tutorial but the directory I've seemingly ruined is essential to the deployment in a production env.

n1k41l
  • 405
  • 2
  • 5
  • 8

2 Answers2

29

A gray folder on GitHub looks like a submodule.
See for instance:

Try in the parent module a git rm --cached sub-directory (no trailing slash).
Check if you have a .gitmodules file at the root of your main repo, with that same sub-directory in it.

See more at "Cannot remove submodule from Git repo"

cd /path/to/parent/respository
git rm --cached submodule-name # no trailing slash: not submodule-name/
git commit -m "Remove submodule entry"
git push

Note the --cached option here: we don't want to remove the sub-folder, only the special entry in the index which marks it as a submodule.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    thanks info was real useful, not sure why but when I ran that command it deleted the directory. So I've scratched it and re-done the project. Wasn't too much effort. – n1k41l Aug 02 '14 at 13:12
  • Do not use "submodule-name/" when using this method. Use "submodule-name". I lagged with this issue. : ( – Pramuditha Jul 16 '20 at 06:38
  • @Pramuditha Good point. I have edited the answer to make that more visible. – VonC Jul 16 '20 at 07:29
  • Where should this be run? In the submodule or in the parent module? – PhilipAllStar Mar 31 '23 at 11:46
  • @PhilipAllStar 9 years later, let me see... yes, in the parent module. I have edited the answer to make that more visible. – VonC Mar 31 '23 at 11:49
-1

I had created a submodule by mistake by using the git init command in both the parent and the subfolder. Just remove the .git directory and start over with one git init command in the proper directory that you want as the top directory.