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.

  • Git add branch on one single directory?
  • The server rejected the connection: None of the protocols were accepted
  • Cannot git clone to VMWare shared folder
  • How to force the update of a gem with bundler?
  • Best approach for git-like interface
  • Git man page seems incorrect
  • 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?

  • Eclipse Git Plugin: cannot Configure Push To Upstream
  • How to ignore files ended with ~ in git?
  • How to allow per user protected branches access in GitLab?
  • Duplicate commits after filter-branch to move root directory
  • git log -p vs. git show vs. git diff
  • GitHub organization access via ssh key
  • 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.