无法通过 SSH 进行 git fetch

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/550787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:35:26  来源:igfitidea点击:

Can't git fetch through SSH

gitversion-controlssh

提问by alamodey

I've setup a git repository one a remote server. Now I'm trying to checkout from it with:

我已经设置了一个 git 存储库和一个远程服务器。现在我试图从它结帐:

git fetch ssh://[email protected]/~username/workfolder/

but I get an error:

但我收到一个错误:

fatal: Not a git repository

What am I doing wrong? Could it be the server does not support Git+SSH?

我究竟做错了什么?会不会是服务器不支持Git+SSH?

回答by Andy Hume

Try

尝试

git clone ssh://[email protected]/~username/workfolder/

Which will create the repository on your local machine. Any commits you make to that branch are to your local repository, and when you want to push back up to the remote server you can run:

这将在您的本地机器上创建存储库。您对该分支所做的任何提交都将提交到您的本地存储库,并且当您想推回远程服务器时,您可以运行:

git push ssh://[email protected]/~username/workfolder/

回答by Emil Sit

git fetchfails because it expects to be run from within an existing git repository. As Andy Hume notes, you must first git cloneto create a local copy of an existing repo.

git fetch失败,因为它希望从现有的 git 存储库中运行。正如 Andy Hume 所指出的,您必须首先git clone创建现有存储库的本地副本。

Further, it defines a git remotecalled originwhich is set to the URL that you cloned from. This is the default remote used when you type git fetchor git pullto retrieve new commits into your local repository, and the default destination when you git pushto push your new local commits out to a remote repository. You do not need to include ssh://[email protected]/~username/workfolder/in your push command if that is where you cloned from.

此外,它定义了一个名为的git remoteorigin,它被设置为您从中克隆的 URL。这是您在本地存储库中键入git fetchgit pull检索新提交时使用的默认远程,以及将git push新本地提交推送到远程存储库时的默认目标。ssh://[email protected]/~username/workfolder/如果您从那里克隆,则不需要包含在您的推送命令中。

Here are some other useful references, from http://gitready.com/:

以下是一些其他有用的参考资料,来自http://gitready.com/

回答by Troy

Could be the tilde ~ Try: ssh://[email protected]/username/workfolder

可能是波浪号 ~ 试试:ssh://[email protected]/username/workfolder