git repo inside a repo

Issue

I accidently make a mistake in my repo, I separately pushed a folder inside my folder into another repo. What I want is to push folder1 back to the mainfolder repo, however when I try to push it I am unable to access the contents on the github user interface. I have already deleted the accidently pushed repo. My repo is organized like this:

-mainfolder
   -folder1  <- I accidently pushed folder1 into another repo
   -folder2
   -folder3
   -folder4
   -README.md

I am getting the warning:

hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of    
hint: the embedded repository and will not know how to obtain it.        
hint: If you meant to add a submodule, use:
hint: 
hint:   git submodule add <url> folder1
hint: 
hint: If you added this path by mistake, you can remove it from the      
hint: index with:
hint: 
hint:   git rm --cached folder1
hint: 
hint: See "git help submodule" for more information.

Solution

Do what the message from Git said to do! It told you:

hint: If you added this path by mistake, you can remove it from the      
hint: index with:
hint: 
hint:   git rm --cached folder1

So do that. To sum up:

rm -rf folder1/.git
git rm --cached folder1
git add folder1

Now commit and push.

Answered By – matt

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published