: $ git filter-branch --subdirectory-filter foodir -- --all
+** Merge a single file (with history) into another repository
+
+Merge the file =myfile= (with history) from =REPO_A= into =REPO_B=.
+
+Create a filtered version of =REPO_A=:
+
+ : $ git clone REPO_A work-a
+ : $ cd work-a
+ : $ SPELL='git ls-tree -r --name-only --full-tree "$GIT_COMMIT" | grep -v "[.]git/\|myfile" | grep -v "^[.]git\$" | tr "\n" "\0" | xargs -0 git rm --cached -r --ignore-unmatch'
+ : $ git filter-branch --prune-empty --index-filter "$SPELL" -- --all
+
+Alter the =grep= stuff as you need. The goal is to remove anything
+you want to keep from the listing produced by =SPELL=.
+
+Merge it into =REPO_B=:
+
+ : $ cd ..
+ : $ git clone REPO_B work-b
+ : $ git remote add myfile-repo ../work-a
+ : $ git pull myfile-repo master
+ : $ git remote rm myfile-repo
+
+Clean up:
+
+ : $ cd ..
+ : $ rm -rf work-a REPO_B
+ : $ mv work-b REPO_B
+
+Thanks to [[http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/][Greg Bayer]] and [[http://stackoverflow.com/questions/7375528/how-to-extract-one-file-with-commit-history-from-a-git-repo-with-index-filter][Peter Hillerström]].
+
** Cherry pick a commit from another repository
First, give the remote repository a nickname (optional)