Search code examples
gitcloneaddition

cannot add a directory containing git cloned subdiretories?


I have a directoryA which contains sub directories which I created via git clone

I want to create a git repository for the directoryA.
But when I do git add -A && git commit -m "w" nothing gets committed.

Do I need to take a special care for dealing with git-cloned subdirectories?

directoryA is my special directory for collection of libraries I use for my project.


Solution

  • What you are creating are uninitialized submodules, and yes submodules require a bit of special handling to use them effectively.

    Once the submodule is initialized, you will be able to commit the sub directory it lives in from the parent project.

    Submodules go beyond basic git with a bit more of a learning curve, but once understood serve their purpose well and merge nicely with the rest of git.

    What makes the handling of submodules special can be summed up in a few key concepts:

    • Submodules must be initialized before the parent repository knows about them.
    • Submodules must be cloned, updated and commited specifically, although there are command options that automate some of this.
    • Submodules are full repositories with a single commit checked out; as such they are headless and a branch must be created before any changes made can be commited.
    • Any changes to submodules should be checked in first, before the changes to the parent repository. The parent update of the submodule is actually an updating of which of the submodules commits the parent knows about.

    Here are a few links that were very helpful to me when I had the need to take the plunge into submodules, which has been quite helpful in keeping track of the various pieces of my projects.

    Git Tools - SubModules

    Git Submodules: Adding, Using, Removing, Updating

    Understanding Git Submodules