How To Move A Git Submodule To An Entirely Different Repository

At some point it may seem like an interesting idea to move one of the submodules in your Git repository to an entirely different URL with completely different commit hashes and history. Here’s how it goes.

  1. Change the submodule URL in your .gitmodules file
  2. Type git submodule sync to sync your repo to the new URL
  3. Type git submodule foreach git pull origin master to pull down new history for all of your submodules
  4. Watch as a complete mess unfolds when it runs into conflicts
  5. Delete the .git/modules/submodule_repo directory and try again
  6. Watch as a complete mess unfolds when it runs into conflicts
  7. Throw your hands up
  8. Remove the submodule completely. See: “Remove a Submodule within git
  9. Add a new submodule in the same location.

Or just start with steps 8 and 9 next time.

Published
Categorized as Code Tagged
Jeremy's profile photo: a selfie taken while walking through Berlin.

Jeremy Felt posted this piece of content on the internet.

Reactions on “How To Move A Git Submodule To An Entirely Different Repository”

Replies

Leave a Reply

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

The only requirement for your mention to be recognized is a link to this post in your post's content. You can update or delete your post and then re-submit the URL in the form to update or remove your response from this page.

Learn more about Webmentions.