Move file from one repository to another repository within a sub-directory

Assistance reqd with GitHub.

Use case is to move files from 1 repo to another but within subfolder of the other repo…and history needs to be retained for the files. What is the right/best way to achieve that?
Note that it may not be possible to move content directly to the new repo first and then move the content to subfolder…since destination repo has some similarly named files…so direct move could cause other types of issues like merge conflicts, etc.

Repo1 contains /src/build.gradle
Repo2 contains /src/build.gradle
Final outcome desired is that Repo1 contains /src/build.gradle and /repo2/src/build.gradle (along with its previous history).
Something like that…

Please give me some suggestions

Hi :wave:

I think you’re talking about submodules!

You won’t be able to do this through the GitHub UI but you’ll be able to accomplish it using the command line with a repository hosted on GitHub.

If you want just one repository instead of submodules, you can do the following:

  • Move files into place within Repo2, e.g. git mv src repo2/src, so you already have the paths where you want the files to end up inside Repo1, hopefully conflict-free.
  • Add Repo2 as a remote of Repo1 and fetch.
  • Merge with the --allow-unrelated-histories flag.