Member-only story
How to Migrate Code in git with history?
You might have come across a scenario in multi-project when you want to move set of files into another repo.
If we try to cut and paste than in that case we will lose git history and we can’t trace it back.
Migrating code with history require following steps:
Step 1: Clone this repo into your local using following command into new folder where you want to setup the repo
git clone --branch <branch_name> --origin origin <repo_url>
Step 2: After cloning repo into local set path of command to repo folder
Step 3: Remove previous origin to avoid accidental changing into old remote
git remove rm origin
Step 4: Filter repo with the required folder
git filter-branch --subdirectory-filter <folder_name> -- --all
Step 5: Clean the unwanted data
git reset --hard
git gc --aggressive
git prune
git clean -fd
Step 6: Add new origin to this repo
git remote add origin <new_repo_url>
Step 7: After performing all the above steps push code to new origin with following command:
git push -u origin <branch_name>
Thanks For Reading, Follow Me for More.