Skip to content

Instantly share code, notes, and snippets.

@tiptronic
Created January 20, 2023 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiptronic/1095fdaa59a67f02f58cab3138823c8a to your computer and use it in GitHub Desktop.
Save tiptronic/1095fdaa59a67f02f58cab3138823c8a to your computer and use it in GitHub Desktop.
git - moving files from one repo to another
```bash
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.
```bash
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/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment