Search code examples
gitclonecommitcherry-pick

Is it possible to cherry-pick a commit from another repository without cloning the entire repository?


I have very limited bandwidth,so I was wondering if it whether it would be possible to get a commit from another repository without actually cloning it. The two repositories have the same file structure but they do not share history at all. Both of them are independent of each other but I still want to cherry-pick a commit from one of them to other. Is this possible ?


Solution

  • Short answer: in theory possible, but not easy to do.

    From "Retrieve specific commit from a remote Git repository", you would need:

    • git repo hosting server with:
      • git 2.5+
      • git config uploadpack.allowReachableSHA1InWant true (on the server side)
    • A shallow clone with single commit fetch (again, git 2.5+, client side)

    That is: you would initialize an empty repo, add the url of the remote origin repo, and:

    git fetch --depth=1 ../testrepo/.git <SHA1>
    

    That would bring only one commit.