-1

Like most git questions, someone has likely already answered this. However, I was unable to find the solution.

I would like to clone one repository into a folder in another repository. However, I am having a hard time justifying a submodule since I would like to keep everything in one repository, I need modify it's contents, it is reasonably small, and it needs to interact with the other code in the first repository.

Ideally I would be able to squash the second repository into one commit and add it into the file structure of the first repository, similar to a pull request of a single folder.

Locke
  • 7,626
  • 2
  • 21
  • 41
  • Do you need the commit history of the repository you want to add? If not, you can add the files as a commit without the repository itself. – Andrew Fan Jan 30 '19 at 17:52
  • 1
    The whole concept of cloning/squashing a second repository into a folder in the first doesn't really make sense, and isn't something you should use Git for. Git's solution to this **is** submodules. If you don't want to use submodules, you should just copy the files from your second repository into your first, or (far better) use whatever code-reuse mechanisms your language provides, like Node modules, Ruby gems, etc. – user229044 Jan 30 '19 at 17:52
  • Possible duplicate of [How to import existing Git repository into another?](https://stackoverflow.com/questions/1683531/how-to-import-existing-git-repository-into-another) – phd Jan 30 '19 at 18:29
  • https://stackoverflow.com/search?q=%5Bgit%5D+import+repository+subdirectory – phd Jan 30 '19 at 18:29

1 Answers1

0

FWIW, I suspect this will lead to trouble, and your argument that you "can't justify" a submodule because, basically, you don't want to... does not instill greater confidence. But as it's not my repo or project, that's just my two cents. So...

It really seems like you're overthinking this. You want to "squash the second repository into a single commit" - in other words, you don't want history, you just want a commit to add the current state of the files to the first repo. So copy the work tree from the second repo into a subdirectory in the work tree of the first repo, git add it and commit.

If you do want the history, or if you want a single commit common to both histories (which could be useful if you have to take later updates from the 2nd repo - though if that's something you anticipate, it again suggests that duplicating the code into the 1st repo may not be advisable), there are ways to do that as well; but thus far, that's not what I'm seeing in your question, so if that's what you want you'll need to clarify the question.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52