能否将Hostinger服务器文件夹设为remote repository并从local machine推送?
直接建立Hostinger远程仓库与本地机器的Git连接方法
一、在Hostinger服务器上创建裸Git仓库
- 通过SSH登录你的Hostinger服务器(可以用Hostinger面板内置终端,或本地终端执行
ssh your-hostinger-username@your-domain.com) - 导航到目标文件夹(你想设置为远程仓库的目录),示例命令:
cd /home/your-username/your-target-folder - 创建裸仓库(无工作目录,专门用于接收推送,避免代码冲突):
其中git init --bare your-repo-name.gityour-repo-name.git是自定义仓库名,.git后缀是裸仓库的常规命名规范。
二、本地Git仓库配置远程连接
- 若本地未初始化Git仓库,先进入项目目录执行:
git init git add . git commit -m "Initial commit" - 将Hostinger远程仓库地址关联到本地Git:
替换命令中的git remote add hostinger ssh://your-hostinger-username@your-domain.com/home/your-username/your-target-folder/your-repo-name.gityour-hostinger-username、your-domain.com及仓库路径为自身实际信息。
三、测试推送与免密配置
- 首次推送时绑定本地分支到远程分支:
(若本地默认分支为git push -u hostinger mainmaster,将main替换为master即可) - 配置SSH免密登录(避免每次推送输入密码):
- 本地终端生成SSH密钥:
全程回车使用默认设置即可。ssh-keygen -t ed25519 -C "your-email@example.com" - 复制本地公钥内容(路径通常为
~/.ssh/id_ed25519.pub) - 登录Hostinger面板,进入Security > SSH Keys,点击Add SSH Key,粘贴公钥内容并保存。
- 本地终端生成SSH密钥:
常见注意事项
- 确保Hostinger服务器上的仓库文件夹权限正确,你的用户拥有读写权限
- 确认Hostinger的SSH端口(默认22)未被本地或服务器防火墙拦截
- 若推送失败,检查远程仓库路径是否输入正确、SSH连接是否正常
内容的提问来源于stack exchange,提问作者Eng_Farghly
相关产品推荐
相关产品推荐

