Moving files from one repo to another with history

Hello Team,

I looking for moving / copy files from one repo to another repo with history details. Both repo having different structure. We are trying to get the whole history of file from repo 1.

Thanks,
Suresh

Fork the repo, if you need to copy from one repo, which is not in your account to another

Hello @sudo-nautilus - Thank you for your response. Can we fork specific files from repo1 to repo2 , if yes please it would be great if you can share the steps.

Thanks,
Suresh

In principle, you can merge a branch from repo 1 to repo 2. git merge refuses to merge unrelated branches by default, but if you really want to there is a flag. It is highly advisable to adjust the directory structure on both sides as needed before merging.

Note that this is only useful if you want to stop using repo 1, and only work on the merged files as part of repo 2 (or continue work independently on both). If you only want to work the files from repo 1 available in repo 2, take a look at submodules.

1 Like

https://docs.github.com/en/get-started/quickstart/fork-a-repo

↑ this is it

Also check the solution provided by @airtower-luna

@airtower-luna - Thank you for the response. The use case which we have repo1 will be my team and repo2 will be neighbor dev team.

We are planning to move only couple of files ( under separate folder) from Repo 2 to Repo 1. We have many other files currently exist in Repo1 that my dev team actively working on this. Also the files we moving ( not copy) , those files are not going for any change in future.

could you think submodules will work for this scenario ?

Thanks,
Suresh

A submodule links a repository into another as a directory. So if you can adjust the paths you use to access those files, it will work. You cannot use a submodule to get only a few selected files, but you’re free to use whatever you like of the submodule.

1 Like