Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace git submodule protocol from git to http

Tags:

git

capistrano

I add a submodule from a git@... URL, to be able to develop in it. Now I want to deploy the app and replace the URL with an git://... one, so it doesn't need authentication to the submodule's repo from Capistrano. Is editing the URL in .gitmodules totally enough to accomplish this?

like image 919
Alexy Avatar asked Jul 08 '11 23:07

Alexy


People also ask

Does git pull also update submodules?

If you track branches in your submodules, you can update them via the --remote parameter of the git submodule update command. This pulls in new commits into the main repository and its submodules. It also changes the working directories of the submodules to the commit of the tracked branch.

Does git clone pull submodules?

It automatically pulls in the submodule data assuming you have already added the submodules to the parent project. Note that --recurse-submodules and --recursive are equivalent aliases.


2 Answers

Editing the .gitmodules file (then committing, and pushing it) will be adequate for any new clones.

Additionally, when a submodule is initialized (e.g. git submodule init …, git submodule update --init …, or git clone --recursive …, etc.) its URL is copied from the .gitmodules file to the repository’s .git/config file.

So, if you have any existing “deployment clones” (the ones you now want to access the submodules through git://… URLs), you will also have to update the URL in their .git/config. You can use git submodule sync to automatically copy the submodule URLs from the current .gitmodules file to your .git/config file (i.e. once you have pulled the commit that updates the .gitmodules file).

The submodule URLs in .git/config are not normally automatically updated because there are cases where you only want to override the URL in certain situations. Specifically, you will often want to use git@… URLs in your repository’s .git/config (so you can push over SSH), but put git://… URLs in .gitmodules (so that the general public does not need to do SSH-based authentication).

like image 184
Chris Johnsen Avatar answered Sep 20 '22 15:09

Chris Johnsen


I experienced similar problems, and after googling, I stumbled on this article: Relative URL for Git submodule. I found it's good a practice to follow as there's no need to manually change the .gitsubmodule file no matter who checks out it. It probably applies to your case as well.

like image 25
ibic Avatar answered Sep 18 '22 15:09

ibic