Git and sub repositories

backupgit

Is there anyway to force git to include files and directories in other repositories that are residing somewhere within the current repository?

The reason I ask is that I have a layout that is something like this:

Projects
  |- Some Project
  |   |- .git
  |- Another Project
  |   |- .git
  |- Yet Another Project
  |   |- .svn
  |- A non versioned Project
  |- etc..

Now what I want to do is git init in Projects and then run a daily cron job that pushes to a bare repository in a folder that is backed up with the following commands

...<set variables>...
git add -A
git commit -m "Automatic Update $Date $Time"
git push --mirror --repo=/backedup/Projects

My plan was to add .git, .svn, .hg, etc to .gitignore and just have this as a safety backup of the files.

Edit: I've got some great suggestions below but I am still curious about if this particular case is possible. Backing the entire folder with rdiff still means backing the inflated files onto my backup media whereas the bare repository takes 4 MB instead of 160 MB, also I just really want to know if it is possible now that I've been thinking about it or I'll lose sleep.

Best Answer

Use git submodules

With submodules, you can plant repositories within other repositories without tracking specific details of the sub-repository's changes.

This feature was specifically created for dealing with projects that may rely on dependences that are tracked elsewhere.

I would give some more detailed use cases but I haven't had reason to use this particular feature yet.

Related Question