How to change git submodule to point to subfolder?

Shooting through a SubModule tutorial , I created a submodule from the boto project. Then I discovered that I really only needed a subset of this project - in particular, boto .

I want to change my submodule to point to this folder. When I look in .gitmodules, I see

[submodule "backup/src/boto"] path = backup/src/boto url = https://github.com/boto/boto.git 

Which URL should be used instead of https://github.com/boto/boto.git ? After I changed the URL, should I delete the boto folder locally and re-pull it out?

+64
git git-submodules
Mar 14 '11 at 19:34
source share
3 answers

I'm afraid that the URL of the submodules always just points to the repository - you cannot specify that you only need a subfolder of the repository, just like git does not support "narrow clones" in general.

If you cannot live with the entire repository as a submodule, you can always create a new repository cloned from boto, and then configure the cron job to:

  • git fetch this repository to a directory
  • Use git filter-branch to update the branch where the subdirectory is at the top level.
  • Add this repository branch as a submodule. However, all this is a bit difficult, and my preference would be to simply have the entire repository as a submodule.
+47
Mar 14 2018-11-11T00:
source share

You cannot clone only part of the repository. This is because git treats the repository as a whole object: when you get it, you get it all .

So, the solution here would be to get a submodule in another directory, and then use a symbolic link to achieve your goal.

+18
Mar 14 2018-11-11T00:
source share

What you want to do is create a branch in the submodule and move the folder up and delete what you don't need. Then you can manage this branch. If you want to undo your changes, you should be able to merge back first. Git will know that you have moved the files and merged successfully.

Hope this helps.

+9
Mar 14 2018-11-11T00:
source share



All Articles