Skip to content

Instantly share code, notes, and snippets.

@pavelosipov
Created July 10, 2021 14:45
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 pavelosipov/3fef77e5604eb324d6f67ba3e3d1afc6 to your computer and use it in GitHub Desktop.
Save pavelosipov/3fef77e5604eb324d6f67ba3e3d1afc6 to your computer and use it in GitHub Desktop.
Cloning folder with related history
# 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