Zum Inhalt springen

Git Submodule Repository Switch

August 11, 2014

Just a quick glance at Git Submodules – they´re really handy to keep Stuff under Version Control that is virtually the same in every Project. If you´ve never heard about the concept, have a look at Git SCM Submodules.

Right now i had to change the Repository of a previously linked Submodule to an other host, so, i changed some of Git´s Files around to reflect that change. And you may probably have ended here through some link or a search and you want to know which files to fix with new Urls.

The Answer is: Don’t.

Git tracks submodules through a multitude of files and in a quite redundant manner, i would say its definitely broken. Hopefully this gets better with Git2.

So, how do you do it? First, delete the Submodules Directory. There, its gone, now you can push it and its done, right ? Wrong.

Git keeps Submodule Info in another file where all the Submodule Info is kept, the „.gitmodules“ in your local Repos Root Folder. Lets see, there should be entries like this:

[submodule „.modman/AvS_FastSimpleImport“]
path = .modman/AvS_FastSimpleImport
url = git@github.com:avstudnitz/AvS_FastSimpleImport.git

I picked a rather popular Magento Extension for your pleasure. As you can see it tracks the Path where the Submodule is stored as well as an alias and a Repo Url. You should delete this entry. Leave the rest untouched.

But you´re still not done. Open the „.git/config“ File of your Project. You will find a copy of the Submodule entry in there. It´s absolutely redundant and tacky, just remove this as you did with the previous entry.

Aaand…you´re still not done. If you try to add the Repo from another Url you´ll be given a notice that the Folder is already configured and could be overwritten if you add the –force parameter. Don´t try that, it will add the Repo with the old Url again.

Actually you descend again in your .git folder and look in the „modules“ Folder. You should find another configuration under a similar folder structure as maintained under your Project Source, but this one holds more Git Configuration. Delete the corresponding Git Config Folder for your Submodule.

Now you commit your Deletions if necessary. Push it. The Submodule is now essentially missing from your project, so, watch any Deployment Settings if you have some.

And now – its really gone. You can add your Submodule now via „git submodule add“ and it will be versioned correctly with the URL you enter. Thats what i meant by „Don´t“. Fixing all these files is a mess and not best practice. Delete the triple-redundant Config Entries and Files and re-add your Submodule, that way you can be sure not to break your git config – plus it´s not really effective to hack the stuff until it works, and you won´t grow any grey hair about it.

From → Sonstiges

Kommentar verfassen

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:


Du kommentierst mit Deinem WordPress.com-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden /  Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden /  Ändern )

Verbinde mit %s

%d Bloggern gefällt das: