将 .netrc 与 SourceForge 和 Git 一起使用

Using .netrc with SourceForge and Git

我知道,这似乎是一个初学者问题,但事实并非如此。我成功地将 .netrc 文件与所有 Git 存储库一起使用,但 SourceForge 上的存储库除外。

我似乎也无法在 SF 文档中找到任何内容。

我基本上是将这些行添加到我的 .netrc 中,但它仍然要求我输入密码:

 machine git.code.sf.net
 login xxxxx
 password xxxxx

 machine api.git.code.sf.net
 login xxxxx
 password xxxxx

我尝试了我能想到的所有其他变体,但我无法让它发挥作用。有没有人做过这个?又如何?

您也可以尝试在该 .netrc 文件中添加协议(考虑到 Git HTTPS URL for SourceForgehttps://<USERNAME>@git.code.sf.net/p/PROJECTNAME/MOUNTPOINT):

machine git.code.sf.net
login <USERNAME>
password xxxxx
protocol https

看看问题是否仍然存在。

确保 git remote -v 返回的 URL(对于远程 'origin')确实包含您的登录信息:

git remote set-url origin https://<USERNAME>@git.code.sf.net/p/PROJECTNAME/MOUNTPOINT
                                  ^^^^^^^^^

如果不起作用,尝试设置GIT_CURL_VERBOSE,以获得更多信息(如in this thread)。


原来 OP purplehuman 使用的是 SSH URL 而不是 HTTPS。

正如我:

  1. SourceForge uses SSH or HTTPS for read/write access.
  2. If you are using SSH, then I confirm that .netrc is not involved in any way: it is used only for providing username/password for a HTTPS URL, not for the SSH passphrase. For the SSH passphrase, (assuming your private SSH key is protected by a passphrase), you would need an ssh-agent, not a .netrc file.

要切换到 HTTPS:

git remote set-url origin https://<USERNAME>@git.code.sf.net/p/PROJECTNAME/MOUNTPOINT

然后 .netrc 文件将被使用(由 curlgit push 中)。