使用SSH代替HTTPS仅用于获取/克隆

时间:2013-11-07 17:12:59

标签: git git-config

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

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

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

[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)

2 个答案:

答案 0 :(得分:3)

看起来很奇怪,你需要将https翻译为https才能正常工作;

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

答案 1 :(得分: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.