Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested GIT Repository mistake method to remove it?

Tags:

git

github

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.

like image 734
n1k41l Avatar asked Aug 02 '14 07:08

n1k41l


People also ask

How do I remove something from a Git repository?

The "rm" command helps you to remove files from a Git repository. It allows you to not only delete a file from the repository, but also - if you wish - from the filesystem. Deleting a file from the filesystem can of course easily be done in many other applications, e.g. a text editor, IDE or file browser.


1 Answers

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

  • "What is this grey git icon?"
  • "What does a grey icon in remote GitHub mean"

Try 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"

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.

like image 149
VonC Avatar answered Oct 21 '22 22:10

VonC