Posts Tagged ‘ Git ’

Changing Git submodule remote repository

A Git submodule allows you to add other repositories inside your project source tree, they’re handful for application modules or plugins, so you can develop reusable plugins independently of your app. When you add submodules, it is created a file called .gitmodules, in your source tree root, where are stored all submodule information (remote repository URL and it’s path on the source tree).
During the development of a project, the source of a submodule may change for any reason (the server URL changed, the repository’s name or path changed, etc…), and you’ll have to update those changes in your apps, otherwise you won’t be able to push or pull on those submodules. This task is not that easy, because Git apart from storing submodule information in the .gitmodules file, it stores the same information in the repository configuration file (.git/config), and every submodule’s repository remote URL. But fortunately, there’s an easier way to do that using the ‘git submodule sync’ command, all you have to do is:

1) Edit the .gitmodules file, and change the URL for the submodules which changed.

2) In your source tree’s root run:

user@host:/path/to/repo$ git submodule sync

3) Then run git init to update the project’s repository configuration with the new URLs:

user@host:/path/to/repo$ git submodule init

And it’s done, now you can continue pushing and pulling your submodules with no problems :)