eedrah
eedrah

Reputation: 2385

Merge only one file from forked git repo

We have two different projects that are forked from the same repo (say, "repo1" and "repo2" from "parent-repo"). I want to copy only one file from repo1 into repo2. What is the "best", "most git-like" way to do this?

(Long time lurker, first time writer; I hope it's OK to put my answer below but I'm hoping someone comes up with something better, as it doesn't seem very good.)

All the repos are hosted on GitHub, but that shouldn't make any difference, right?

Upvotes: 1

Views: 102

Answers (2)

eedrah
eedrah

Reputation: 2385

This is what I have so far:

git remote add sister-repo https://github.com/username/repo1.git
git fetch sister-repo
git checkout sister-repo/master sharedfiles/file1.file

Advantages

  • Done entirely by the command line

Disadvantages

  • Have to fetch the whole repo for one file (problem if it is large, although if they share history it will be smaller)

Upvotes: 1

Harrison Ray
Harrison Ray

Reputation: 159

One way to do this would be to add and commit your one file to repo1 and issue a pull request to parent-repo. Repo2 would then have access to the file by running git fetch upstream.

If you did not want to issue a pull request to parent-repo you could also have repo1 fork your repo2 then add your file to the forked repo2 and issue a pull request to repo2

Upvotes: 2

Related Questions