Skip to content

Instantly share code, notes, and snippets.

@dansuh17
Forked from ryaninvents/unsubmodule.md
Created May 29, 2018 06:10
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dansuh17/b8c26b4d76989a70164def551800cadd to your computer and use it in GitHub Desktop.
Save dansuh17/b8c26b4d76989a70164def551800cadd to your computer and use it in GitHub Desktop.
Convert git submodule to regular directory

From Stack Overflow.

# Fetch the submodule commits into the main repository
git remote add submodule_origin git://url/to/submodule/origin
git fetch submodule_origin

# Start a fake merge (won't change any files, won't commit anything)
git merge -s ours --no-commit submodule_origin/master

# Do the same as in the first solution
git rm --cached submodule_path # delete reference to submodule HEAD
git rm .gitmodules             # if you have more than one submodules,
                               # you need to edit this file instead of deleting!
rm -rf submodule_path/.git     # make sure you have backup!!
git add submodule_path         # will add files instead of commit reference

# Commit and cleanup
git commit -m "removed submodule"
git remote rm submodule_origin
@cpres
Copy link

cpres commented Mar 30, 2023

worked perfectly!

@imkarimkarim
Copy link

💛

@b23prodtm
Copy link

very nice job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment