1

Locally I have a folder of a big project that contains many folders of sub projects.

I have 2 Git Repositories:

Big Project Repo (bitbucket) - contains all sub projects - in this repo I save all source files of the project and exclude all the compiled files. This repo serves as a backup of the source code.

Sub Project A Repo (heroku) - nested in the big project's folder, this is a production repo where I save compiled files only of Sub Project A and exclude all source files.

Sub Project A Repo is pushed as expected, no problems there.

Big Project Repo on the other hand, is pushed mostly as expected, with the exception of Sub Project A's folder being referred to by a gitlink instead of saving the actual files.

I'd like to store in the big project repo the actual files of sub project A folder, treating sub project A as a regular folder rather than a repo in this case.

Some searching brought up git submodules, but after reading a little about them I get the impression that the files will still not be stored the way I want that way, it'll simply take into account the reference to the nested repo when cloning the big repo. The nested repo's files will still not be stored in the big repo.

Let me know if I got this right and your thoughts on how to solve this.

Royi Bernthal
  • 882
  • 4
  • 17
  • 45

1 Answers1

0

I confirm that submodule will not store the subrepo files in the parent repo.
It will use the gitlink, and add the remote url of your nested repo in a .gitmodules.

If you want to include your nested repo into the main one:

  • First, git rm nestedRepo (no trailing slash): you need to remove the gitlink
  • Second, use ingydotnet/git-subrepo: you will endi up with one big repo easy to clone, while preserving the nested repo history and individual updates.
    It is easier than using subtrees.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Do I make sub project A a subrepo via **git subrepo init** and that's it? If so, wouldn't it break my existing heroku repo in sub project A? Wouldn't I also need to make the big project repo a subrepo for it to work? (resulting in a subrepo containing a subrepo) – Royi Bernthal May 20 '17 at 12:27
  • @RoyiBernthal the idea is to include those subrepos into your *local* big repo, and pushing back the big repo to heroku, this time with all the files of the subrepos. – VonC May 20 '17 at 14:04
  • How do I include those subrepos into my local big repo? – Royi Bernthal May 20 '17 at 14:43
  • By first removing the current nested repo content, and then their git links (the git rm in my answer). (commit that deletion) Then by `git subrepo clone []` those repos back into your main repo locally. Commit and push your main repo (which now includes all the files of the nested repos) – VonC May 20 '17 at 14:46
  • `git rm server` - **fatal: pathspec 'server' did not match any files**. The folder 'server' is clearly there, though it appears under untracked files in `git status` if that matters. – Royi Bernthal May 20 '17 at 15:10
  • If it is untracked, you can simply delete it (simple rm) – VonC May 20 '17 at 15:12
  • Do you mean literally delete the folder in windows? It's the sub project A I was referring to, I need that folder. Do I need to track it? `git add` "tracks it" for a specific commit and then the tracking is reset, correct me if I'm wrong. Otherwise, what do you mean by a simple rm? As you can see I'm new to Git. – Royi Bernthal May 20 '17 at 15:16
  • I understood from your question that subfolder is a Git repo of its own, so sure, delete the folder, then clone it back in with git-subrepo. That is the all idea of this answer – VonC May 20 '17 at 15:17
  • It is. Do you mean clone that subfolder back in from the heroku git remote into my local big project git and then push the big project git? If so, then the problem is on heroku I'm pushing compiled files from that subfolder, while in the big project I'd like to push source files from that same subfolder. The big project git focuses on different file types than the heroku git that exist in the same subfolder, its purpose is not to contain an exact copy of the files pushed to heroku git, but rather of different files in the same local subfolder. – Royi Bernthal May 20 '17 at 15:28
  • Yes, clone it back from whatever remote url the nested Git repo came from, heroku or otherwise. You still can do heroku work from that same repo cloned locally elsewhere on your computer – VonC May 20 '17 at 15:31
  • Can you please read my edit? Doing what you said won't solve my issue to the best of my understanding. – Royi Bernthal May 20 '17 at 15:32
  • I will as soon as I back home. I am typing everything on my phone – VonC May 20 '17 at 15:33
  • @RoyiBernthal "The big project git focuses on different file types than the heroku git that exist in the same subfolder, its purpose is not to contain an exact copy of the files pushed to heroku git, but rather of different files in the same local subfolder.". OK. My answer was simpler: you have a nested repo reference (gitlink), but you want its files instead: git subrepo will do that. I don't know enough about heroku for your particular case: I would manage two different sets of files of one repo in two different branches of said repo. – VonC May 20 '17 at 19:47
  • "delete the folder, then clone it back in with git-subrepo" - this is how I imagine it: http://i.imgur.com/igaJsn2.png There's nothing special about heroku you can treat it as any other git. "My answer was simpler: you have a nested repo reference (gitlink), but you want its files instead: git subrepo will do that." - I understand, though I am still struggling with the how. I have no doubt it's simple and I'm simply not looking at it correctly. "I would manage two different sets of files of one repo in two different branches of said repo." - is that an alternative solution? – Royi Bernthal May 20 '17 at 22:33
  • @RoyiBernthal First, compiled files are generally not part of a Git repo: they are regenerated. Second, you can make the sources part of your big repo with http://stackoverflow.com/a/40896383/6309 (instead of completely deleting the dir. And you would git subrepo your compiled repo back into the big project: it would then have both: sources and compiled. – VonC May 20 '17 at 22:39
  • True, generally they are not, though git is what heroku uses in order to host generated files, that's git's purpose in this case. I think it makes sense to me now. I followed this http://stackoverflow.com/a/40896383/6309 `rm --cached` sounds like it should do the job, however after I deleted the "server" dir, added all files, commited and pushed my changed, the gitlink to "server" still appears on bitbucket. – Royi Bernthal May 21 '17 at 00:07
  • @RoyiBernthal The only reason why a gitlink still appear on BitBucket would be if you did not delete the `.git` folder under your subrepo: that is what makes a nested repo nested: the presence of a `.git` folder: when you do the `git rm --cached`, you don't remove any file from the local disk, so you need to `rm` (not `git rm`) the `subrepo/.git subfolder` as well, before `git add`, `commit` and `push`. – VonC May 21 '17 at 05:41
  • If I remove that git folder I remove all my heroku configurations. Am I suppose to delete that git folder, make this subfolder a subrepo, then reconfig the subrepo for heroku? – Royi Bernthal May 21 '17 at 14:03
  • @RoyiBernthal First, was that folder, as I understood from your question, a git repo of its own, with its own remote repo url? Had it a .git subfolder in it, which would explain why the parent repo only records it as a gitlink? If yes, my answer stands, and yes, you would have rm it and git subrepo it back into your main parent repo. – VonC May 21 '17 at 14:04
  • Something still doesn't make sense to me here but I find it hard to phrase myself differently. By any chance was such a thing done before? Are there any examples out there which I can see and learn from? – Royi Bernthal May 22 '17 at 20:02
  • @RoyiBernthal Not that I know of. Again my answer is not so much about the specifics of heroku, just about the general principle of removing a nested repo (that is a subfolder with a .git in it), and replacing it by its full content. – VonC May 22 '17 at 20:03
  • Yes that I understand, it doesn't really matter to me that it's heroku. The thing I find hard to understand is how to clone back a nested git which I was never able to save on remote in the first place - the source of the "server" folder, it need to be on remote so that I could clone it back to local, yet I am not able to upload it to remote in the first place because of this issue. You probably already explained it in different ways and I simply didn't understand. – Royi Bernthal May 22 '17 at 23:29