VMware Linux 20.04无法访问远程Git仓库的解决方案咨询
解决Linux虚拟机无法访问远程Git仓库的可行方案
方案1:基于Windows中转仓库同步(适配现有操作流程)
你之前用裸仓库的问题在于裸仓库未关联远程,改成带远程关联的中转仓库即可实现双向同步:
- 在Windows主机创建关联远程的中转仓库(不要用
--bare):git clone git.myremoterepo.com ./windows-git-relay - 将这个中转仓库放入VMware共享文件夹,确保Linux虚拟机可访问该路径
- 在Linux虚拟机克隆共享文件夹中的中转仓库作为开发库:
git clone /mnt/hgfs/shared/windows-git-relay ./dev-repo - 提交代码到远程流程:
- Linux开发库内提交后推送到中转仓库:
git push origin master - 切换到Windows主机的中转仓库,推送到真正的远程:
cd ./windows-git-relay git push origin master
- Linux开发库内提交后推送到中转仓库:
- 拉取远程更新流程:
- Windows中转仓库先拉取远程最新代码:
git pull origin master - Linux开发库从中转仓库拉取更新:
cd ./dev-repo git pull origin master
- Windows中转仓库先拉取远程最新代码:
方案2:让Linux通过Windows主机代理访问远程
如果Windows主机可正常联网,可配置代理让Linux直接访问远程仓库:
- 确认Windows主机的局域网IP(比如
192.168.1.100),并在Windows上开启本地HTTP/SOCKS代理(端口假设为1080) - 在Linux虚拟机全局配置Git代理:
若仅需单个仓库生效,进入仓库目录执行:git config --global http.proxy http://192.168.1.100:1080 git config --global https.proxy https://192.168.1.100:1080
配置完成后,Linux内的Git可直接与远程仓库交互。git config http.proxy http://192.168.1.100:1080 git config https.proxy https://192.168.1.100:1080
方案3:使用Git Bundle离线同步(适合低频率更新场景)
无需持续共享文件夹,通过bundle文件传递代码:
- Windows主机生成全量bundle文件:
git clone git.myremoterepo.com ./temp-repo cd temp-repo git bundle create ../full-repo.bundle --all - 将
full-repo.bundle放入共享文件夹,Linux虚拟机克隆该bundle:git clone /mnt/hgfs/shared/full-repo.bundle ./dev-repo - Linux开发完成后生成增量bundle:
cd ./dev-repo # 生成master分支从上次同步到当前的增量提交,可根据实际时间调整 git bundle create ../update.bundle master@{3 days ago}..master - Windows主机导入增量并推送到远程:
cd ./temp-repo git pull ../update.bundle master git push origin master
内容的提问来源于stack exchange,提问作者megaMind
相关产品推荐
相关产品推荐

