I've been looking for a way to move a directory in a git repository to a new repository and preserve the history. We are reorganizing some code at work so that's what prompted me to start looking. The scenario is I have a repository and structure that looks like the following:
I want to move directory1 and all of the files in that directory(file1a, file1b, file1c) to a new git repository and preserve the change history. I want to end up with the following:
The solution is here. I started with this solution but with the second solution I ended up with the files from my directory1 in the root of the repo. By the time I moved the files into a new directory1 the change history was stored in the root directory of the new repo so if I was in directory1 in repoB I would need to type git log --follow file1a to actually get the full history. Not a big deal but with the first solution listed my directory structure follows, so no need to git mv the files, AND my change log is with the file in the new repo and directory.