Git: Push a local git submodule, including submodule files, to a remote bare repository

穿精又带淫゛_ 提交于 2019-12-08 03:37:59

问题


I have two local projects which I manage with git, one being dependent on the other – like this:

project A/
├── project B/     
│   ├── file B₁
│   ├── file B₂
│   ├── …

It makes sense to me to have project B as a git submodule of project A.

Now, I have set up a remote bare repository for project A for backup and sharing purposes. Of course, I want the remote repository to contain all of project B, including its files (file B₁, file B₂, …). But git push and git push --recurse-submodules=on-demand don’t achieve this. Whenever I list the files in my remote repository by git ls-tree -r HEAD, only the files of project A itself are listed. This does make sense to me.

However, is there a way to push the entire submodule project B to my remote base repository somehow, preferably in a clean way?


回答1:


If B is actually a submodule, you should have a .gitmodule referencing it.
In that .gitmodule file, you would see the remote repo URL where B is pushed, in case there is any new commits done in B.

But B being a submodule means A won't have B files in it, only a reference to B SHA1.

If you want, you can un-submodule B (with my answer or this one) in order to keep all the B files in A.




回答2:


A submodule has to have a separate repository. Create a new bare repo and push your submodule to it.



来源:https://stackoverflow.com/questions/48936752/git-push-a-local-git-submodule-including-submodule-files-to-a-remote-bare-rep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!