Search code examples
gitbranchmergegit-branch

Can I pull only certain files from another git repository?


For instance, suppose I have Repository 1 and Repository 2. Repository 1 has a file /a/b/c/d. Would it be possible for me to import this file into Repository 2 as /e/f/g/h?

The reason being that I want to pull in changes from an experimental branch from a different git repository. I tried merging everything together, but there were a ton of conflicts (of every kind). Therefore, I doubt that I can merge the entire branch in, but I would like to try to bring in as much as I can.

Is there any way to do what I want to do, or am I just going to have to resort to copying files directly?


Solution

  • You can get files from the remote repository using git archive. You could then add and commit the files to your repository. This approach will not preserve history from his branch. See git archive docs for details.

    If you want to try to preserve parts of that experimental branch, you could git fetch his repository, and then git rebase his experimental branch onto your repository, editing or skipping commits with conflicts as appropriate. Once you have a cleaned up branch in your repository, you can merge that in. See git rebase docs