You may want to look into git subtree.
Have a look at these two articles :
Its documentation is not served on git-scm.org (I couldn't say why), you can read it by typing git help subtree, or by reading it from the source code in git's repo :
Technically, you can include a repo within itself as a submodule ; the unusual stuff would come from :
- the commits that would be checked out at the submodule's directory,
- the branch names,
- the history of the commts for the submodule.
Suppose your code looks like this :
Readme.md
libs/util/fileA.py
libs/util/fileB.py
src/main.py
and you would like to have the content of libs/util/ as a "self hosted" submodule.
- about the commits for the submodule :
This would mean that the complete content of a certain commit of your repo should be :
fileA.py
fileB.py
You would have, in the same repo, commits that represent "the full project" and commits that represent "just the util lib" sitting one next to another.
This is perfectly manageable, just surprising at first.
- about the branch names :
since your repo probably already has a branch named master which represents the state of your "complete" project, you can't use that name for a branch of the "submodule" part.
The simplest way would be to choose a set of names dedicated to that submodule (for example : util/*) and stick to it.
- about the history :
It wouldn't make much sense to have in the same branch commits for the complete repo and commits for the submodule only. The branches dedicated to the submodule would have no relation with the branches of the "complete" project.
Again : git can perfectly manage that. Here is one way to create such a starting branch in your repo :
# from your repo's 'master' branch :
git checkout -b util/master
git filter-branch --subdirectory-filter libs/util
When you look at how git-subtree works, it allows you to handle the same kind of setup : unrelated branches stored within the same repo, and checking out a sub branch at a location you choose.
Its main advantage is : since it was intended to work that way from the beginning, the commands will probably give you less friction, and less way to mess things up in your repo.