git - 当我使用 SSH 时,我使用 -i 开关,我是否也需要为我的 GIT 远程执行此操作?

标签 git ubuntu

我正在我的服务器上设置 GIT,当我通过 SSH 连接到我的服务器时:

ssh -i /path/to/key -p 30000 user@1.1.1.1

现在我在服务器上设置 GIT,我这样设置 REMOTE:

remote add origin ssh://user@1.1.1.1:30000/path/to/git/repo/proj1

我收到错误:

推原点 没有共同的引用,也没有指定;什么也不做。 也许您应该指定一个分支,例如“master”。 fatal: 远端意外挂断 错误:无法将某些引用推送到“ssh://user@1.1.1.1:30000/path/to/git/repos/proj1”

到目前为止,在我的本地仓库中我做了:

touch .gitignore
git add .
git commit -m 'init'

我的服务器里面有一个 git bare。

更新

git push origin

git push origin
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://git.myhost/home/myuser/gitrepos/csf'

我的 .ssh/config:

Host git.myhost
        User myuser
        Hostname 1.2.3.4
        Port 30000
        IdentityFile /home/myuser/.ssh/key_for_git

最佳答案

如何在.ssh/config 文件中设置您的主机信息; 这样,您就不需要在 sshgit 中使用 -i

编辑:小谷歌搜索我找到了这个

https://git.wiki.kernel.org/index.php/GitTips#How_to_pass_ssh_options_in_git.3F

因此,除了 .ssh/config 之外,唯一的解决方案是使用 $GIT_SSH 环境变量。

关于git - 当我使用 SSH 时,我使用 -i 开关,我是否也需要为我的 GIT 远程执行此操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4292717/

相关文章:

node.js - 在 WebStorm 和 SourceTree 中使用 NVM 时 Git Hooks 错误

Git Checkout 与 git bash 一起无限期挂起。怎么解决?

php - 如何使用 PHP7 使 mssql_connect 工作?

python - 从 cron 作业修改 crontab

git - 添加环境变量以提交消息

git - 在 merge 到 master 之前我如何在其他分支上工作?

linux - 安装驱动程序会增加 linux 内核内存占用吗?

windows - 是否可以在 Ubuntu Virtual box 机器中运行 Vagrant box?

c++ - 在我的 main.cpp 中使用外部类

git - svn 到 git 迁移 : incomplete history