Created
July 10, 2021 14:45
-
-
Save pavelosipov/3fef77e5604eb324d6f67ba3e3d1afc6 to your computer and use it in GitHub Desktop.
Cloning folder with related history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's consider some demo repository contains foo folder in its | |
# root along with some other stuff. We want to make clone of foo | |
# and preserve the history of commits for the files inside it. | |
# The new name for the foo's clone will be bar. | |
# The steps | |
# 1. Installing required dependency https://github.com/newren/git-filter-repo | |
# brew install git-filter-repo | |
# 2. Cloning 2 instances of the repository. The first one will be | |
# using as a merge target with original history. In the second | |
# one we will filter commits related to a cloning folder and | |
# rename it. | |
git clone git@github.com:account/demo.git demo | |
git clone git@github.com:account/demo.git demo_with_copy_paste | |
# 3. Filtering history related to cloning folder and renaming it | |
cd demo_with_copy_paste | |
git filter-repo --path foo --path-rename foo:bar | |
# 4. Merging repository with foo's clone named bar into original repository | |
cd ../demo | |
git remote add demo_with_copy_paste ../demo_with_copy_paste | |
git fetch demo_with_copy_paste | |
git merge demo_with_copy_paste/master --allow-unrelated-histories |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment