Cherry-pick single commit from other Git repository

Francesco Vezzoli

To perform a cherry-pick one commit form repository placed in another folder, just run the following command:

$ git --git-dir=../<some-other-repo>/.git format-patch -k -1 --stdout <commit SHA> | git am -3 -k

This command create a patch from the repository in the some-other-repo’s of 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).