【问题标题】:Pushing a branch to a remote server fails将分支推送到远程服务器失败
【发布时间】:2014-09-11 13:02:04
【问题描述】:

我有一个在远程服务器上使用 Git 的项目。我为 Mac 安装了SourceTree 来管理它。我在根目录中还有一个 .ssh 文件夹,其中包含我的所有项目,公钥在服务器中。

我能够成功地克隆项目,甚至可以毫无问题地提交+推送它。然后我在本地仓库中创建了一个分支,添加了一个新文件并尝试提交+推送它。它已提交,但推送失败并显示以下错误消息。

Pushing to git@gitserver:gitbtest

ssh: Could not resolve hostname gitserver: nodename nor servname provided, or not known

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我不确定为什么会这样。有没有办法在 SourceTree for Mac 中设置 SSH 密钥?我似乎找不到任何选择这样做。

任何解决此问题的帮助都会很棒。

谢谢!

【问题讨论】:

  • 在从 repo/master 成功推送到从分支推送的时间之间,您是否进行了任何更改?
  • 在测试从master推送后,我刚刚创建了一个分支,添加了一个新文件并尝试将其推送到服务器。就在那时出现了这个问题。
  • 你有$HOME/.ssh/config 文件吗?
  • 不,我的 .ssh 文件夹中只有这 3 个文件。 id_rsa, id_rsa.pub, known_hosts

标签: macos git ssh atlassian-sourcetree


【解决方案1】:

git@gitserver:gitbtest 之类的 url 只有在有 ssh 配置文件以解析名称 gitserver 时才能工作:

$HOME/.ssh/config

Host gitserver
   Hostname xxx.xxx.xxx.xxx # IP or full name for gitserver
   User git
   IdentityFile ~/.ssh/id_rsa

其实有了这样的文件,你甚至不用指定用户:

git remote set-url origin gitserver:gitbtest

(您可以查看“git public key for more repositories”中使用的 ~/.ssh/config 文件的示例)

【讨论】:

  • 知道了!非常感谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-20
  • 2018-05-02
  • 2022-01-15
  • 1970-01-01
  • 2011-09-10
  • 2016-07-08
  • 1970-01-01
相关资源
最近更新 更多