Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

  |- 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.

share|improve this question
so, essentially you want incremental backups of a directory containing files? why do you want to enforce "git" to do this? – akira Jul 30 '10 at 7:48
Also, be aware your cron job would push out the current working copy in each of your nested repositories. Depending on what you've been working on, this might be a step back. – Lawrence Velázquez Jul 30 '10 at 8:14
@akira The backup of a bare repository for the Projects folder would be very small and easy to send through ssh, compared to the backup of the inflated files and it would include at least a daily history of the working set. Perhaps there are a lot better applications for this that stores the data + deltas compressed my initial thought however was Git would do this incredibly well. – Don Jul 30 '10 at 9:02
a) ssh has a compression option, b) an incremental backup program normally sends only differences, check out, c) with incremental backup you have "version history" as well, d) the point i was making is this: enveloping everything in git just because one can is not always the best solution for a problem. – akira Jul 30 '10 at 11:05
I'm well aware of most of the points you make though I have not used rdiff before, thanks a bunch for the link. I'll be sure to check it out! However I'm still curious for a solution to the question asked for various reasons so I'll leave it open. – Don Jul 30 '10 at 11:40

2 Answers 2

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.

share|improve this answer

This particular case is not possible. And not practical.

  • Nested Git repo would be detected and the git add -A at the root directory wouldn't take into account the nested .git sub-directories.
  • .svn would work but that would need a .gitignore carefully calibrated to ignore everything else.

A separate backup job with an incremental copy over a compressed ssh, as suggested by akira in the comments, is a better solution.

share|improve this answer
can't this be achieved via submodules perhaps? – Tobias Kienzler Sep 23 '10 at 13:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.