Использование SSH вместо HTTPS только для Fetch/Clone

StackOverflow https://stackoverflow.com/questions/19842282

  •  29-07-2022
  •  | 
  •  

Вопрос

Я хотел бы сделать все клонирование/тяги, чтобы получить данные из SSH, но продолжать использовать HTTPS для push.

Моя команда всегда будет использовать HTTPS (git clone https://), и я не могу изменить это (много скидков с использованием), но я хотел бы заставить клон использовать SSH и продолжать использовать HTTPS для Push.

Что я сделал (в этом порядке):

[url "ssh://server/"]
insteadOf = "https://server/"
[url "https://server/"]
pushInsteadOf = "ssh://server/"

Но как получение, так и push переводятся в SSH:

$ git remote -v
origin  ssh://server/repo.git (fetch)
origin  ssh://server/repo.git (push)

И я хотел бы увидеть что -то вроде этого:

$ git clone https://server/repo.git
$ git remote -v
origin  ssh://server/repo.git (fetch)
origin  https://server/repo.git (push)
Это было полезно?

Решение

Как бы странно ни странно, вам нужно перевести HTTPS на HTTPS, чтобы он работал;

[url "ssh://server/"]
insteadOf = "https://server/"
[url "https://server/"]
pushInsteadOf = "https://server/"

Другие советы

Использовать git remote set-url --push. Анкет Из документации:

set-url
  Changes URL remote points to. Sets first URL remote points to
  matching regex <oldurl> (first URL if no <oldurl> is given)
  to <newurl>. If <oldurl> doesn’t match any URL, error occurs and
  nothing is changed.

    With --push, push URLs are manipulated instead of fetch URLs.
    With --add, instead of changing some URL, new URL is added.
    With --delete, instead of changing some URL, all URLs matching
      regex <url> are deleted. Trying to delete all non-push URLs is an error.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top