Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git submodules using relative urls

I use git (TortoiseGit 1.7.5.0) and have a repo with submodules, which are referenced via absolute paths in a manner:

[submodule "common/sub"]
path = common/sub
url = ssh://localhost/lib/common/sub

While the super-repo is cloned as ssh://user@localhost/super, the username shouldn't go into each submodule url, because different users should work with the code using their own credentials.
When pulling/pushing submodules I had to enter my login (the password is not needed because I'm running Pageant): the username isn't passed to TortoisePlink via command line.

Surfing the Web, I found several posts mentioning relative urls for submodules, but apparently such approach doesn't work well with TortoiseGit: I tried several formats - the program often crashes. Anyway I succeeded with the format like:

[submodule "common/sub"]
path = common/sub
url = ../common/sub

The file .git/config is populated with the proper absolute urls, but after that TortoiseGit just crashes...

I've reviewed other options including:

  1. use gitolite (as proposed here) or sdorra (as proposed here), but this looks like an overcomplicated solution.

  2. follow subtree merge strategy (as proposed here). It looks like a nice approach.

One of the working workarounds is to initialize the submodule with a "non-standard" URL as explained at the end of git Submodules Explained (the link was found here).

I suppose some simpler workaround may help in my case (like providing default login in some local config file or via command line), but I haven't found any workable hints for that.

And the question: what is the easiest way of using submodules without hard-coded user names in absolute urls?

like image 597
AntonK Avatar asked Dec 01 '11 16:12

AntonK


People also ask

Are git submodules a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.

When should I use git submodules?

In most cases, Git submodules are used when your project becomes more complex, and while your project depends on the main Git repository, you might want to keep their change history separate. Using the above as an example, the Room repository depends on the House repository, but they operate separately.

How do submodules work in git?

A git submodule is a record within a host git repository that points to a specific commit in another external repository. Submodules are very static and only track specific commits. Submodules do not track git refs or branches and are not automatically updated when the host repository is updated.

Does git pull pull submodules?

Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .


1 Answers

Actually relative urls works fine with msysgit already. I've upgraded it from 1.7.7.1 to 1.7.8, and crashes are gone. Great! :)

like image 139
AntonK Avatar answered Sep 21 '22 01:09

AntonK