git clone <git repository A url>
cd <git repository A directory>
git remote rm origin
git filter-branch --subdirectory-filter <directory 1> -- --all
mkdir -p <target-path in="" repo-b="">
git mv -k * <target-path in="" repo-b="">
git add .
git commit
Make a copy of repository B if you don’t have one already. On line 3, you’ll create a remote connection to repository A as a branch in repository B. Then simply pull from this branch (containing only the directory you want to move) into repository B. The pull copies both files and history. Note: You can use a merge instead of a pull, but pull worked better for me. Finally, you probably want to clean up a bit by removing the remote connection to repository A. Commit and you’re all set.
git clone <git repository B url>
cd <git repository B directory>
git remote add repo-A-branch <git repository A directory>
git pull repo-A-branch master
git remote rm repo-A-branch
Source: http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/
@wevtimoteo - I am familiar with
git log --follow
for finding the full history of a file.My comment is the method above for moving files from one repository to another "with history" doesn't actually provide all the history. The method presented above doesn't follow a file that has been moved.
This only provides the history up to the point that the file has been moved or renamed.