How to move a directory from one git repository to another one preserving the history
These simple steps will let you move a directory contained within a git repository into another one while preserving the history.
- Make the root directory of the source git repository current.
- Execute the following command to export the directory you want to move
git log --pretty=email --patch-with-stat --reverse --full-index --binary -- directory-to-export > /tmp/exportfile
- Before importing the exported directory, you can tweak the destination directory. For example, you can import the directory content right into the current directory by removing directory-to-export/ in /tmp/exportfile
- Clone the project you want to import into.
- Make this project directory current
- Import the exported directory in step 2 using the following command
git am < /tmp/exportfile
- Push the project directory.