Is it possible to cherry-pick a commit from another git repository?

The answer, as given, is to use format-patch but since the question was how to cherry-pick from another folder, here is a piece of code to do just that:

$ git --git-dir=../<some_other_repo>/.git \
format-patch -k -1 --stdout <commit SHA> | \
git am -3 -k

Explanation from Cong Ma comment Aug 28 ’14

git format-patch command creates a patch from some_other_repo’s commit
specified by its SHA (-1 for one single commit alone). This patch is
piped to git am, which applies the patch locally (-3 means trying the
three-way merge if the patch fails to apply cleanly).

Leave a Comment