0

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

我的命令将始终使用 https ( git clone https://) 并且我无法更改它(使用大量脚本)但我想强制克隆使用 SSH,并继续使用 HTTPS 进行推送。

我做了什么(按此顺序):

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

但是 fetch 和 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)
4

2 回答 2

3

看起来很奇怪,您需要将 https 转换为 https 才能正常工作;

[url "ssh://server/"]
insteadOf = "https://server/"
[url "https://server/"]
pushInsteadOf = "https://server/"
于 2013-11-07T17:24:20.640 回答
0

使用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.
于 2013-11-07T17:16:19.270 回答