Git Submodule update over https
Asked Answered
S

3

54

I am sitting on a proxy which only allows http/https traffic only, I am able to clone a repository from Github, but I have to fetch/push using the https URL and username/password.

Now my issues is a repository with submodules, when I execute git submodule update it times out, and I can only assume this is because it's using an SSH connection which is blocked. (it doesn't even ask me for a password on private repos)

Sycophancy answered 10/7, 2012 at 9:7 Comment(1)
This question also addresses the issue with a Permission denied (publickey) error.Colquitt
N
47

In your .gitmodules file in the root of your repo, and in the .git/config file, you should find a section for your submodule. You can edit the url there so it is accessed via https request rather ssh.

Of course it may already be an ssh url, in which case the problem may be something else, but this is the first place to check.

Necaise answered 10/7, 2012 at 9:9 Comment(3)
This was very helpful but my problem was slightly more complex in that I had subrepos inside subrepos. Here is how I got all the correct files edited in Linux: sed -i -e 's/git:\/\//http:\/\//g' .gitmodules; find . -name config -type f -exec sed -i -e 's/git:\/\//http:\/\//g' {} \;Papua
Running git submodule sync after editing .gitmodules, as François Koessler's answer suggests, is a necessary step for this to work!Isbell
I hadn't read your comment. I had to manually change the .git/config fileMonosyllabic
G
93
  1. Edit your .gitmodules file to use the HTTPS URL.
  2. Run git submodule sync to reflect the change to your .git/config file.
  3. Run the update command again.
  4. Commit and push the changes in your .gitmodules file.

Example .gitmodules file:

[submodule "vendor/engines/fat_free_crm"]
    path = vendor/engines/fat_free_crm
    url = https://github.com/fatfreecrm/fat_free_crm.git

Credits: https://mcmap.net/q/339708/-replace-git-submodule-protocol-from-git-to-http

Gleanings answered 17/6, 2015 at 7:35 Comment(1)
My .gitmodules already has https://github.com/ at the start and .git at the end, but when running git submodule update --init it still tries to run over SSH, since it says "Host key verification failed", and fatal: clone of '[email protected]:. This is a public repo so I just want to use HTTPS but it keeps trying to use SSH.Bateau
N
47

In your .gitmodules file in the root of your repo, and in the .git/config file, you should find a section for your submodule. You can edit the url there so it is accessed via https request rather ssh.

Of course it may already be an ssh url, in which case the problem may be something else, but this is the first place to check.

Necaise answered 10/7, 2012 at 9:9 Comment(3)
This was very helpful but my problem was slightly more complex in that I had subrepos inside subrepos. Here is how I got all the correct files edited in Linux: sed -i -e 's/git:\/\//http:\/\//g' .gitmodules; find . -name config -type f -exec sed -i -e 's/git:\/\//http:\/\//g' {} \;Papua
Running git submodule sync after editing .gitmodules, as François Koessler's answer suggests, is a necessary step for this to work!Isbell
I hadn't read your comment. I had to manually change the .git/config fileMonosyllabic
M
6

If you don't want to manually change the .gitmodules file yourself, you can do it with git CLI now (make sure your git version is not too old).

This will make the changes for you:

git submodule  set-url [--] <path> <newurl>

Example:

git submodule set-url somedir https://github.com/somename/somerepo.git
Marlie answered 1/12, 2021 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.