Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robertomiranda/1ed790cb0f5afb60889c3a7faf55c905 to your computer and use it in GitHub Desktop.
Save robertomiranda/1ed790cb0f5afb60889c3a7faf55c905 to your computer and use it in GitHub Desktop.

To transfer a directory from one Git repository to another while preserving its history, follow these steps:

  1. Clone the SOURCE REPOSITORY to your local machine.
  2. Remove the origin from the local copy of the SOURCE REPOSITORY.
git remote remove origin
  1. Use Git filter-repo to filter the repository's history to include only the files you need, specifying the DIRECTORY_PATH.
git filter-repo --path DIRECTORY_PATH --force
  1. Move the filtered results to the desired folder in the local copy of the SOURCE REPOSITORY.
  2. Add the new remote origin to the target repository using
git remote add origin git@github.com:userame/repo-name.git.
  1. Pull the changes from the remote repository using to sync the local and remote target repositories.
git pull --allow-unrelated-histories
  1. Create a new branch using
git checkout -b BRANCH_NAME.
  1. Push the changes to the target repository using git push origin HEAD.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment