different push/pull urls for git submodule

I’m using the git superproject pattern in a large project which is deployed by a Teamcity build agent which does not have a repository account, however the repository is set up to allow anonymous cloning. For this reason I have set up the submodules with their http:// url rather than their git url. The issue with this is that the repository rejects http pushes:

Total 0 (delta 0), reused 0 (delta 0)
error: RPC failed; result=22, HTTP code = 401
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly

So every time I update the submodules when switching branches, I have to do a git remote add-url --push to add the git:// url.

  • How can I store keychain credentials for multiple Github accounts?
  • svn and git versioning models difference
  • Sync TFS and GIT
  • Lost git history after reorganizing project folder
  • Git repository in OneDrive synced folder
  • Git: Error creating pull request: Forbidden (HTTP 403)
  • Is there any way to set up the submodules in the superproject such that they already use the http:// url for pulling and the git:// url for pushing?

  • Moving all commits beyond initial commit off master
  • “git push all” (multiple repositories) doesn't work
  • Append git's branch name to command prompt
  • How do I merge a sub directory in git?
  • what's the Git equivalent of TFS commands shelve/unshelve? cherry-pick?
  • How can I determine the URL that a local Git repository was originally cloned from?
  • One Solution collect form web for “different push/pull urls for git submodule”

    The LibreOffice project also uses submodules and includes:

    By default you submodules repository is in a state called ‘detached HEAD’ that means that the commit checked-out — which is the one that the super-project (core) need — is not associated with a local branch name.

    Don’t forget to add a correct pushurl for the submodule you are working on or you will not be able to commit.

    $ editor .git/modules/submodule/config

    And in the section [remote "origin"] add:

    pushurl = ssh://logerrit/submodule

    (similar to soulseekah’s comment) (in your case, use a git:// address)

    You can also do it through (within a submodule)

    git config remote.origin.pushurl git://...

    If you don’t, as illulstrated in this project, you would get a:

    fatal: The remote end hung up unexpectedly
    Git Baby is a git and github fan, let's start git clone.