Git Remote指向Windows Server的SSH URL正确格式咨询
解决Git通过SSH推送至远程Windows Server的路径格式问题
问题根源
你当前的Git Remote URL格式错误:远程Windows Server的路径不能直接写c:/Users/...,因为SSH会话中Git会按照类Unix的路径规则解析,c:/会被识别为相对路径而非Windows的盘符绝对路径,导致找不到仓库。
正确的SSH URL格式(两种可选)
格式1:大写盘符+无冒号+正斜杠路径
ssh://user@localhost:2202/C/Users/User/PSComputerManagementZp.git
格式2:盘符前加双斜杠(兼容部分Windows SSH环境)
ssh://user@localhost:2202//c/Users/User/PSComputerManagementZp.git
修复步骤
- 删除错误的远程配置
git remote remove win_test
- 添加正确的远程(二选一)
# 使用格式1 git remote add win_test ssh://user@localhost:2202/C/Users/User/PSComputerManagementZp.git # 或者使用格式2 git remote add win_test ssh://user@localhost:2202//c/Users/User/PSComputerManagementZp.git
- 验证远程配置
git remote -v
- 测试推送(替换
main为你的实际分支名)
git push win_test main
额外验证项
- 确认远程Windows Server上的仓库是裸仓库,需在目标目录执行:
git init --bare PSComputerManagementZp.git
- 确保SSH登录用户对该仓库目录有完整的读写权限
内容的提问来源于stack exchange,提问作者Little Train
相关产品推荐
相关产品推荐

