<p>With SVN, I had a single big repository I kept on a server, and checked-out on a few machines. This was a pretty good backup system, and allowed me easily work on any of the machines. I could checkout a specific project, commit and it updated the 'master' project, or I could checkout the entire thing.</p>

<p>Now, I have a bunch of git repositories, for various projects, several of which are on github. I also have the SVN repository I mentioned, imported via the git-svn command..</p>

<p>Basically, I like having all my code (not just projects, but random snippets and scripts, some things like my CV, articles I've written, websites I've made and so on) in one big repository I can easily clone onto remote machines, or memory-sticks/harddrives as backup.</p>

<p>The problem is, since it's a private repository, and git doesn't allow checking out of a specific folder (that I could push to github as a separate project, but have the changes appear in both the master-repo, and the sub-repos)</p>

<p>I <em>could</em> use the git submodule system, but it doesn't act how I want it too (submodules are pointers to other repositories, and don't really contain the actual code, so it's useless for backup)</p>

<p>Currently I have a folder of git-repos (for example, ~/code_projects/proj1/.git/ ~/code_projects/proj2/.git/), and after doing changes to proj1 I do <code>git push github</code>, then I copy the files into ~/Documents/code/python/projects/proj1/ and do a single commit (instead of the numerous ones in the individual repos). Then do <code>git push backupdrive1</code>, <code>git push mymemorystick</code> etc</p>

<p>So, the question: How do your personal code and projects with git repositories, and keep them synced and backed-up?</p>

[{'answer_id': 36905, 'author': 'Spoike', 'author_id': 3713, 'author_profile': 'https://Stackoverflow.com/users/3713', 'pm_score': 2, 'selected': False, 'text': '<p>,I haven\'t tried nesting git repositories yet because I haven\'t run into a situation where I need to. As I\'ve read on the <a href="http://irc://irc.freenode.net/git" rel="nofollow noreferrer">#git channel</a> git seems to get confused by nesting the repositories, i.e. you\'re trying to git-init inside a git repository. The only way to manage a nested git structure is to either use <a href="http://git-scm.com/docs/git-submodule" rel="nofollow noreferrer"><code>git-submodule</code></a> or Android\'s <a href="http://source.android.com/source/using-repo.html" rel="nofollow noreferrer"><code>repo</code></a> utility. </p>\n\n<p>As for that backup responsibility you\'re describing I say <strong>delegate</strong> it... For me I usually put the "origin" repository for each project at a network drive at work that is backed up regularly by the IT-techs by their backup strategy of choice. It is simple and I don\'t have to worry about it. ;)</p>\n'}, {'answer_id': 37006, 'author': 'Damien Diederen', 'author_id': 3844, 'author_profile': 'https://Stackoverflow.com/users/3844', 'pm_score': 7, 'selected': True, 'text': '<p>I would <strong>strongly</strong> advise against putting unrelated data in a given\nGit repository.  The overhead of creating new repositories is quite\nlow, and that is a <em>feature</em> that makes it possible to keep\ndifferent lineages completely separate.</p>\n\n<p>Fighting that idea means ending up with unnecessarily tangled history,\nwhich renders administration more difficult and--more\nimportantly--"archeology" tools less useful because of the resulting\ndilution.  Also, as you mentioned, Git assumes that the "unit of\ncloning" is the repository, and practically has to do so because of\nits distributed nature.</p>\n\n<p>One solution is to keep every project/package/etc. as its own <em>bare</em>\nrepository (i.e., without working tree) under a blessed hierarchy,\nlike:</p>\n\n<pre><code>/repos/a.git\n/repos/b.git\n/repos/c.git\n</code></pre>\n\n<p>Once a few conventions have been established, it becomes trivial to\napply administrative operations (backup, packing, web publishing) to\nthe complete hierarchy, which serves a role not entirely dissimilar to\n"monolithic" SVN repositories.  Working with these repositories also\nbecomes somewhat similar to SVN workflows, with the addition that one\n<em>can</em> use local commits and branches:</p>\n\n<pre><code>svn checkout   --&gt; git clone\nsvn update     --&gt; git pull\nsvn commit     --&gt; git push\n</code></pre>\n\n<p>You can have multiple remotes in each working clone, for the ease of\nsynchronizing between the multiple parties:</p>\n\n<pre><code>$ cd ~/dev\n$ git clone /repos/foo.git       # or the one from github, ...\n$ cd foo\n$ git remote add github ...\n$ git remote add memorystick ...\n</code></pre>\n\n<p>You can then fetch/pull from each of the "sources", work and commit\nlocally, and then push ("backup") to each of these remotes when you\nare ready with something like (note how that pushes the <em>same</em> commits\nand history to each of the remotes!):</p>\n\n<pre><code>$ for remote in origin github memorystick; do git push $remote; done\n</code></pre>\n\n<p>The easiest way to turn an existing working repository <code>~/dev/foo</code>\ninto such a bare repository is probably:</p>\n\n<pre><code>$ cd ~/dev\n$ git clone --bare foo /repos/foo.git\n$ mv foo foo.old\n$ git clone /repos/foo.git\n</code></pre>\n\n<p>which is mostly equivalent to a <code>svn import</code>--but does not throw the\nexisting, "local" history away.</p>\n\n<p>Note: <em>submodules</em> are a mechanism to include shared <em>related</em>\nlineages, so I indeed wouldn\'t consider them an appropriate tool for\nthe problem you are trying to solve.</p>\n'}, {'answer_id': 779812, 'author': 'imz -- Ivan Zakharyaschev', 'author_id': 94687, 'author_profile': 'https://Stackoverflow.com/users/94687', 'pm_score': 5, 'selected': False, 'text': '<p>I want to add  to <a href="https://stackoverflow.com/a/37006/623735">Damien\'s answer</a> where he recommends:</p>\n\n<pre><code>$ for remote in origin github memorystick; do git push $remote; done\n</code></pre>\n\n<p>You can set up a special remote to push to all the individual real remotes with 1 command; I found it at <a href="http://marc.info/?l=git&amp;m=116231242118202&amp;w=2" rel="nofollow noreferrer" title="a Linus&#39; message">http://marc.info/?l=git&amp;m=116231242118202&amp;w=2</a>:</p>\n\n<blockquote>\n  <p>So for "git push" (where it makes\n  sense to push the same branches\n  multiple  times), you can actually do\n  what I do:</p>\n  \n  <ul>\n  <li><p>.git/config contains:</p>\n\n<pre><code>[remote "all"]\nurl = master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6\nurl = login.osdl.org:linux-2.6.git\n</code></pre></li>\n  <li><p>and now <code>git push all master</code> will push the "master" branch to <em>both</em><br>\n  of those remote repositories.</p></li>\n  </ul>\n</blockquote>\n\n<p>You can also save yourself typing the URLs twice by using the contruction:</p>\n\n<blockquote>\n<pre><code>[url "&lt;actual url base&gt;"]\n    insteadOf = &lt;other url base&gt;\n</code></pre>\n</blockquote>\n'}, {'answer_id': 2731946, 'author': 'Danny G', 'author_id': 328168, 'author_profile': 'https://Stackoverflow.com/users/328168', 'pm_score': 2, 'selected': False, 'text': "<p>I also am curious about suggested ways to handle this and will describe the current setup that I use (with SVN).  I have basically created a repository that contains a mini-filesystem hierarchy including its own bin and lib dirs.  There is script in the root of this tree that will setup your environment to add these bin, lib, etc... other dirs to the proper environment variables.  So the root directory essentially looks like:</p>\n\n<pre><code>./bin/            # prepended to $PATH\n./lib/            # prepended to $LD_LIBRARY_PATH\n./lib/python/     # prepended to $PYTHONPATH\n./setup_env.bash  # sets up the environment\n</code></pre>\n\n<p>Now inside /bin and /lib there are the multiple projects and and their corresponding libraries.  I know this isn't a standard project, but it is very easy for someone else in my group to checkout the repo, run the 'setup_env.bash' script and have the most up to date versions of all of the projects locally in their checkout.  They don't have to worry about installing/updating /usr/bin or /usr/lib and it keeps it simple to have multiple checkouts and a very localized environment per checkout.  Someone can also just rm the entire repository and not worry about uninstalling any programs.</p>\n\n<p>This is working fine for us, and I'm not sure if we'll change it.  The problem with this is that there are many projects in this one big repository.  Is there a git/Hg/bzr standard way of creating an environment like this and breaking out the projects into their own repositories?</p>\n"}, {'answer_id': 3435806, 'author': 'arxpoetica', 'author_id': 209803, 'author_profile': 'https://Stackoverflow.com/users/209803', 'pm_score': 1, 'selected': False, 'text': "<p>There is another method for having nested git repos, but it doesn't solve the problem you're after.  Still, for others who are looking for the solution I was:</p>\n\n<p>In the top level git repo just hide the folder in .gitignore containing the nested git repo.  This makes it easy to have two separate (but nested!) git repos.</p>\n"}, {'answer_id': 12762439, 'author': 'imz -- Ivan Zakharyaschev', 'author_id': 94687, 'author_profile': 'https://Stackoverflow.com/users/94687', 'pm_score': 2, 'selected': False, 'text': '<p>What about using <a href="http://joeyh.name/code/mr/" rel="nofollow">mr</a> for managing your multiple Git repos at once:</p>\n\n<blockquote>\n  <p>The mr(1) command can checkout, update, or perform other actions on a\n  set of repositories as if they were one combined respository. It\n  supports any combination of subversion, git, cvs, mercurial, bzr,\n  darcs, cvs, vcsh, fossil and veracity repositories, and support for\n  other revision control systems can easily be added. [...]</p>\n  \n  <p>It is extremely configurable via simple shell scripting. Some examples\n  of things it can do include:</p>\n  \n  <p>[...]</p>\n  \n  <ul>\n  <li>When updating a git repository, pull from two different upstreams and merge the two together.</li>\n  <li>Run several repository updates in parallel, greatly speeding up the update process.</li>\n  <li>Remember actions that failed due to a laptop being offline, so they can be retried when it comes back online.</li>\n  </ul>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/36862', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/745/']