Skip to content

Instantly share code, notes, and snippets.

@jacksonpires
Forked from niartenyaw/remove-submodule.sh
Created February 11, 2021 22:08
Show Gist options
  • Save jacksonpires/b5a148af3ed8898995b103ecbdd9a66c to your computer and use it in GitHub Desktop.
Save jacksonpires/b5a148af3ed8898995b103ecbdd9a66c to your computer and use it in GitHub Desktop.
App Academy - Remove unwanted submodule from nested Git repos and re-add all the files inside of it
# In most cases, a single Rails app will be attached to a single repo
# As of Rails 5.1, initializing a new project will also automatically initialize Git
# This is perfect in most circumstances, but at App Academy, students have homework and
# project repos that contain multiple rails apps inside them
# To account for this without pushing the submodules, students need to remove the .git
# directory before adding and commiting the new project, but most do not, resulting in
# unwanted submodules and missing work in the repo
# This gist is intended to walk through how to remove the submodule and re-add the missing
# files inside that directory
# NOTE:
# ONLY do this if you do not care about tracking previous commits associated with the
# submodule repo
# Navigate to the directory above the submodule
cd path/to/dir
# Tell git to remove the submodule from its tracking
git rm -r --cached sub_module_folder
# Check to see that the submodule folder is untracked
git status
# Remove the submodule's .git
# MAKE SURE TO INCLUDE THE TRAILING /.git
rm -rf sub_module_folder/.git
# Now add the folder
git add sub_module_folder
# Check that all the files have been added
git status
# Commit the submodule's folder and push!
git commit -m "Fix submodule"
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment