Skip to content

Instantly share code, notes, and snippets.

@FezVrasta
Forked from whistler/import.sh
Last active June 30, 2020 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FezVrasta/64d415f395dfc7354563136b8ef63e4d to your computer and use it in GitHub Desktop.
Save FezVrasta/64d415f395dfc7354563136b8ef63e4d to your computer and use it in GitHub Desktop.
Copy files to another repository while saving git history
# copied from http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/
git clone <git repository A url> # clone source repository
cd <git repository A directory>
git remote rm origin # to make sure it doesn't affect the original repository
git filter-repo --path <directory 1> # remove all files other than the ones needed
mkdir <directory 1> # move them into another directory where they will be stored in the destination repository (if needed)
mv * <directory 1>
git add .
git commit -m "moved to <directory 1>"
cd ..
git clone <git repository B url> # clone destination repository
cd <git repository B directory>
git remote add repo-A-branch <git repository A directory> # add source as a remote
git pull repo-A-branch master --allow-unrelated-histories # pull
git remote rm repo-A-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment