我想强制所有克隆/拉力以从SSH获取数据,但继续使用HTTP进行推动。

我的命令将始终使用https(git clone https://)我无法更改此(使用大量的滚动),但我想强迫克隆使用SSH,并继续使用HTTPS进行推动。

我(按以下顺序)做了什么:

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

但是,提取和推动都被翻译成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)
有帮助吗?

解决方案

看起来很奇怪,您需要将HTTP转换为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