Moving A Folder from One Git Repo to Another While Keeping History

Moving stuff from one git repo to another while keeping the history intact is a cool way to break stuff out of old repos and migrate them around. Here’s how to do it:

1
2
3
4
5
6
7
8
9
10
11
12
13
git clone --no-hardlinks /path/to/sourcerepository directory-to-move
cd directory-to-move

# remove remote origin just so we can't break anything in the source repository
git remote rm origin

# filter for desired files
git filter-branch --subdirectory-filter new-directory-name HEAD

# move around files, etc.
# then commit
git add .
git commit -m "isolated files"

Refernece: Moving files from a Git repository to another keeping history