How to move a directory from one git repository to another one preserving the history

L'Antre du Tryphon

schedule
2021-04-11 | 00:35h
update
2021-10-15 | 01:55h
person
www.ctheroux.com
domain
www.ctheroux.com

How to move a directory from one git repository to another one preserving the history

Advertisement

These simple steps will let you move a directory contained within a git repository into another one while preserving the history.

  1. Make the parent directory of the source git repository current.
  2. 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
  3. 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
  4. Clone the project you want to import into.
  5. Make this project directory current
  6. Import the exported directory in step 2 using the following command
    git am < /tmp/exportfile
  7. Push the project directory.

Advertisement

Imprint
Responsible for the content:
www.ctheroux.com
Privacy & Terms of Use:
www.ctheroux.com
Mobile website via:
WordPress AMP Plugin
Last AMPHTML update:
10.09.2025 - 00:53:07
Privacy-Data & cookie usage: