Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save taarimalta/9a17ef3ac756278b127816cca378c6ed to your computer and use it in GitHub Desktop.
Save taarimalta/9a17ef3ac756278b127816cca378c6ed to your computer and use it in GitHub Desktop.
Move code from a repo to a monorepo as a subdirectory

Move code in old repo to a subdirectory

cd <oldRepo>
git filter-repo --to-subdirectory-filter <module-name> --force

# Note branch Name
git branch

Clone target repo

cd ..
git clone <target-repo>
cd <target-repo-folder>
git checkout -b <new-feature-branch>

Add old repo as remote in new repo

git remote add src-repo ../old-repo-folder/
git pull src-repo <old-repo-branch-name> --allow-unrelated-histories

Push as feature branch

git push origin <new-feature-branch>

Then create a PR from <new-feature-branch> in the target repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment