Skip to content

Instantly share code, notes, and snippets.

@Mohitsharma44
Created April 19, 2017 21:54
Show Gist options
  • Save Mohitsharma44/0b062bf828ff984968957f50039dda84 to your computer and use it in GitHub Desktop.
Save Mohitsharma44/0b062bf828ff984968957f50039dda84 to your computer and use it in GitHub Desktop.
Adding a particular subfolder (from another git repo) to another subfolder (of other git repo) preserving the history

This is definitely not the best method but this is something that worked for me

  • clone the Repo (from where you want the subdirectory)
git clone --no-hardlinks repo2
  • Select the folder you want to keep
cd repo2
git filter-branch --subdirectory-filter path/to/subfolder HEAD -- --all
  • Remove everything else
git reset --hard
git gc --aggressive
git prune
git remote rm origin
  • Add the Repo where you want this subdirectory in and clone it
git remote add origin repo1
git pull origin master --allow-unrelated-histories
  • Commit and Push
git add --all -A
git commit -m "whatever"
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment