gitfilepullanyremote-repository

Git pull all commits referring to a single file in remote repo unrelated to my local repo


I would like to pull this file (there are 3 commits so far) via Git into my own local repository, which isn't related to that GitHub repo at all. Is it possible to somehow pull all commits related to this specific file?

In other words is it possible to download any file (meaning commits related to it) located in any arbitrary repository - which is not added as a remote in my repo nor cloned - I have access to?

If I understand Git correctly - I can pull changes from remote branch to local branch by first fetch'ing them, but my repo has to have added repo of such branch as a remote. If so, is it just as simple as adding new remote repo and just pulling specific branch (or even cherry-pick only desired commits), and that should just create new branch in my local repo with all or chosen (cherry-picked) commits?


Solution

  • You're best bet is to checkout the individual file and commit each rev.

    git remote add new_repo PATH_TO_REPO.git
    git fetch new_repo
    git checkout <SHA> -- my_file.txt
    git add my_file.txt
    

    Repeat for each commit