2

I would like following setup:

  • Having one main projectsfolder
  • in this projects folder I have many other folders (including foreign git repositories)

Usecase

Sync the whole projects folder to a local git repo (my usb stick) to be able to keep my whole personal project structure in sync between two computers. But all foreign git repos should stay and keep working.

I'm using TortoiseGIT, is there any possibility to do what I want? Having a personal super git repo that contains many individual sub repos?

prom85
  • 16,896
  • 17
  • 122
  • 242

1 Answers1

1

Having a personal super git repo that contains many individual sub repos?

This is mainly what git submodules are for.
Your main project will record:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Would never have checked submodules as I was looking for a supermodule, but seems to be what I need, thanks. Is it necessary to create the super repo first and add the sub modules afterwards or is it possible to "wrap" a folder with many potential sub modules in a new parent git repo? If I create a repo in a folder that already contains foreign sub repos, will this make problems? – prom85 Nov 16 '16 at 09:42
  • @prom85 tes: adding nested git repo will only record their gitlinks, not their remote url.You can convert them though: http://stackoverflow.com/questions/28412699/how-to-add-an-existing-nested-repo-already-checked-out-in-a-subdir-to-a-parent. Or http://stackoverflow.com/a/6106503/6309. Also: http://stackoverflow.com/q/28306781/6309 – VonC Nov 16 '16 at 09:45
  • Thanks, I think I'll get this working now. Will try it – prom85 Nov 16 '16 at 09:49
  • I have on further question: if I sync a submodule with changes to my usb folder, it will tell me the submodule is dirty. How can I sync the dirty submodule to the usb folder without syncing the submodule to it's master branch? – prom85 Nov 18 '16 at 18:12
  • 1
    @prom85 you need to keep both the submodule and the parent repo in sync: if the submodule changes, it needs to commit and push, and then the parent need to add its new SHA1, commit and push. So your usb folder should include also a bare repo for the main repo (the one which includes all submodules), in order to push both: main repo and submodules. – VonC Nov 18 '16 at 18:16
  • Ok, understand. Does this mean I have to commit and push all submodules one by one as well? Or can this be done in one step? – prom85 Nov 18 '16 at 18:54
  • 1
    @prom85 See http://stackoverflow.com/a/10878273/6309: with `git config push.recurseSubmodules on-demand`, a simple `git push` pushes everything you need (changed submodule *and* parent repo, all in one go) – VonC Nov 18 '16 at 21:08
  • I've solved this by pushing my sub modules to github. Then I can push the new hashes to my usb drive. To sync local changes between my local sub module and the usb folder, I need to create a remote reposititory on my usb stick for each project, am I right? This can't be automatically managed by the parent repo as it is handling the sub modules via the hashes, is this correct? – prom85 Nov 21 '16 at 06:56
  • @prom85 working with submodules, you shouldn't have to create remote repo since the .gitmodules includes already the remote repo url. A git submodule update --init is enough to get back their content on a new clone, and you also have the option to make those submodule follow their respective master branch: http://stackoverflow.com/a/9189815/6309 – VonC Nov 21 '16 at 06:58
  • But I can't sync my local folder to the usb folder if my sub modules have local changes, git asks me to push the changes to the remote url (which I don't want, I want the changes in my local repositiy only) – prom85 Nov 21 '16 at 07:01
  • @prom85 if the remote url for your submodule is one pointing back to your usb key, you should be able to comit and push back those change to said usb key, facilitating the sync between the two compuiters. – VonC Nov 21 '16 at 07:03
  • So I have to have to add a remote url on my usb stick for each sub module and then I can sync to the usb stick? That's what the I meant actually – prom85 Nov 21 '16 at 07:06
  • Yes, a remote url for each submodule pointing to a bare repo (one for each submodule) on the USB key. – VonC Nov 21 '16 at 07:10
  • Was hoping the parent repo can manage this somehow... But then I think that I understand each step that I have to do know. Thanks – prom85 Nov 21 '16 at 07:11
  • By that, I mean that the parent repo .git modules file will include url referencing the bare repo USB path – VonC Nov 21 '16 at 07:11
  • So yes, the parent repo does manage it, as those remote URLs are registered in the.gitmodules file – VonC Nov 21 '16 at 07:12