2025年3月18日Memo跨项目共享本地 Git 子模块配置Git配置现有子模块 修改子模块 URL S 是子模块名称。 cd /path/to/parent_repo # 进入父仓库(A/B/C) git config submodule.S.url /projects/S # 指向你的本地仓库 强制重新初始化 rm -rf S # 删除旧子模块 git submodule update --init --force 附加配置(若报错) 如果出现 transport 'file' not allowed: git config --global protocol.file.allow always 新增子模块 按常规方式添加子模块(生成远程URL配置) git submodule add https://github.com/example/S.git S 修改本地子模块的URL配置(覆盖远程地址) git config submodule.S.url /projects/S 初始化子模块(强制使用本地路径) git submodule update --init --force 关键注意事项 安全限制 新版 Git 默认禁用本地文件协议克隆,可能需执行步骤3 作用范围 仅影响本地环境,远程仓库不受影响 版本跟踪 各父仓库仍需独立提交子模块版本更新
跨项目共享本地 Git 子模块配置
配置现有子模块
S 是子模块名称。
cd /path/to/parent_repo # 进入父仓库(A/B/C) git config submodule.S.url /projects/S # 指向你的本地仓库rm -rf S # 删除旧子模块 git submodule update --init --forcetransport 'file' not allowed:新增子模块
关键注意事项