Clearing Submodules in Git

2014-02-11

I have a site that I inherited and at first, I just set up git repos in the subfolders I was working on, however, as time went on it seemed to be a better idea to have the entire site be one large repo. I didn’t formally set up submodules, but when I would run git status on the top level repository, it looked like this:

#       modified:   www/reports/compliance/cds (modified content, untracked content)
#       modified:   www/reports/pic2 (modified content)
#       modified:   www/reports/standard/degree/time2deg (modified content)
#       modified:   www/reports/standard/enrollment/dailyEnrollment/report.php
#       modified:   www/reports/standard/factbook (new commits, modified content, untracked content)
#       modified:   www/reports/standard/financial (modified content)

I wanted to keep the history from the sub-repos and this link was a major help, but I didn’t do exactly what they said, so I thought I’d document it here.

  1. git remote add submodule_origin path/to/sub/repo
  2. git fetch submodule_origin
  3. git merge -s ours –no-commit submodule_origin/master
  4. git rm –cached path/to/sub/repo
  5. rm -rf path/to/sub/repo/.git
  6. git add path/to/sub/repo
  7. git commit -m “removed submodule”
  8. git remove rm submodule_origin
Written on February 11, 2014