You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否将Hostinger服务器文件夹设为remote repository并从local machine推送?

直接建立Hostinger远程仓库与本地机器的Git连接方法

一、在Hostinger服务器上创建裸Git仓库

  1. 通过SSH登录你的Hostinger服务器(可以用Hostinger面板内置终端,或本地终端执行ssh your-hostinger-username@your-domain.com)
  2. 导航到目标文件夹(你想设置为远程仓库的目录),示例命令:cd /home/your-username/your-target-folder
  3. 创建裸仓库(无工作目录,专门用于接收推送,避免代码冲突):
    git init --bare your-repo-name.git
    
    其中your-repo-name.git是自定义仓库名,.git后缀是裸仓库的常规命名规范。

二、本地Git仓库配置远程连接

  1. 若本地未初始化Git仓库,先进入项目目录执行:
    git init
    git add .
    git commit -m "Initial commit"
    
  2. 将Hostinger远程仓库地址关联到本地Git:
    git remote add hostinger ssh://your-hostinger-username@your-domain.com/home/your-username/your-target-folder/your-repo-name.git
    
    替换命令中的your-hostinger-username、your-domain.com及仓库路径为自身实际信息。

三、测试推送与免密配置

  1. 首次推送时绑定本地分支到远程分支:
    git push -u hostinger main
    
    (若本地默认分支为master,将main替换为master即可)
  2. 配置SSH免密登录(避免每次推送输入密码):
    • 本地终端生成SSH密钥:
      ssh-keygen -t ed25519 -C "your-email@example.com"
      
      全程回车使用默认设置即可。
    • 复制本地公钥内容(路径通常为~/.ssh/id_ed25519.pub)
    • 登录Hostinger面板,进入Security > SSH Keys,点击Add SSH Key,粘贴公钥内容并保存。

常见注意事项

  • 确保Hostinger服务器上的仓库文件夹权限正确,你的用户拥有读写权限
  • 确认Hostinger的SSH端口(默认22)未被本地或服务器防火墙拦截
  • 若推送失败,检查远程仓库路径是否输入正确、SSH连接是否正常

内容的提问来源于stack exchange,提问作者Eng_Farghly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 02:48:21