• Home
  • Git
  • Programming
  • Leadership
  • About

Git Fetch Victor

Git, Programming and so much more...

Git Repository in a Repository Fix

Written by vjpudelski on August 31, 2015

In working with apprentices new to Git and really new to source control in general, I have come across a couple cases where someone will have a repository defined within a repository. In these cases the parent repository is not tracking the files within the subdirectory and there appears to be nothing that can be done to resolve this. To paint a better picture let’s work with this example:

project
|
+ sub_project

In this example there is a .git directory within both the project folder and the sub_project folder. Thus Git believes that these are separate repositories and in fact by design, although not correctly defined, believes that sub_project is a submodule of the project repository. I say not correctly defined since it cannot be found in a .gitmodules file. It only appears to be a submodule. We would have some work to do if we wanted it to be correctly defined. However, in the simple case we don’t want to do this and instead want to remove the repository from the subdirectory.

To fix the issue we need to delete the .git folder in the sub_project directory. We also need to remove the directory from the index of the project repository so that we may re-add the directory and be able to track the files within the sub_project directory in the project repository. To do this we can run the git rm sub_project command. Thus to fix the issue:

1. delete the .git folder from the subdirectory
2. run git rm sub_project
3. re-add the sub_project directory to the project repository
4. commit

Now things should be ok and we should be able to continue using our project repository with no issues. We just need to be careful not to create repositories within the project directory unless we really want to have submodules.

UPDATE: 9/11/2015

In doing this again I did have to run git rm with the --cached

git rm --cached sub_project

Posted In Git | Programming | Troubleshooting
Tagged git | source control

Post navigation

PreviousMy Git commit isnt adding my files…
NextNew to Git… What is git?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Leaders Eat Last
  • Java calling .NET WebAPI
  • So What Really Mattered?
  • What really matters?
  • Has It Really Been Over a Year!

Recent Comments

  • Jason King on Has It Really Been Over a Year!
  • Sarah Dutkiewicz on Changing the Past
  • Dave Balzer on Team Culture
  • Sarah Dutkiewicz on Team Culture
  • Sarah Dutkiewicz on Impostor Syndrome, my dealings…

Archives

  • April 2019
  • February 2019
  • January 2018
  • October 2017
  • September 2016
  • August 2016
  • July 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • August 2015
  • January 2015

Categories

  • Git
  • Leadership
  • Non-Technical
  • Personal
  • Programming
  • Raspberry Pi
  • Reviews
  • Troubleshooting
  • Unstoppable Course

Tags

aspnet aspnetcore books coaching CodeMagazine cron csharp culture dotnet dotnetcore dreams git iPhone java management nike Nozbe Raspian rsync running samba server source control SubtleArtOfNotGivingAFck teams vscode web hosting

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright © 2025. Git Fetch Victor
Powered By WordPress and Auspicious