Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I sync files in two different git repositories (not clones) and maintain history?

Tags:

git

I maintain two different git repos that need to share some files, and I'd like the commits in one repo to show up in the other. What's a good way to do that for ongoing maintenance in each repo?

I've been one of the maintainers of the perlfaq (Github), and recently I fell into the role of maintaining the Perl core documentation, which is also in git.

Long before I started maintaining the perlfaq, it lived in a separate source control repository. I recently converted that to git. Periodically, one of the perl5-porters would sync the shared files in the perlfaq repo and the perl repo. Since we've switched to git, we'e been a bit lazy converting the tools, and I'm now the one who does that. For the time being, the two repos are going to stay separate.

Currently, to sync the FAQ for a new (monthly) release of perl, I'm almost ashamed to say that I merely copy the perlfaq*.pod files in the perlfaq repo and overlay them in the perl repo. That loses history, etc. Additionally, sometimes someone makes a change to those files in the perl repo and I end up overwriting it (yes, check git diff you idiot!). The files do not have the same paths in the repo, but that's something that I could change, I think.

What I'd like to do, in the magical universe of rainbows and ponies, is pull the objects from the perlfaq repo and apply them in the perl repo, and vice-versa, so the history and commit ids correspond in each.

  • Creating patches works, but it's also a lot work to manage it
  • Git submodules seem to only work to pull in the entire external repo
  • I haven't found something like svn's file externals, but that would work in both directions anyway
  • I'd love to just fetch objects from one and cherry-pick them in the other

What's a good way to manage this?

like image 681
brian d foy Avatar asked Dec 07 '09 19:12

brian d foy


People also ask

How do I merge two git repository and keep history?

To combine two separate Git repositories into one, add the repository to merge in as a remote to the repository to merge into. Then, combine their histories by merging while using the --allow-unrelated-histories command line option.


1 Answers

The subtree merge strategy, combined with the script git subtree, might help here.
It would work for push and pull.
It has still some issue with merges, although Git1.7.0 will fix that with a '-Xsubtree' option, but it still worth looking into.

like image 147
VonC Avatar answered Oct 16 '22 18:10

VonC