1

We are separating one of our systems into smaller components. We created new Git repository "new" based on existing Git repository "old".

Eventually some code will be dropped from "old" and maintained solely in "new".

However currently this code is still being maintained in "old". While this situation continues how can we merge across repositories from "old" to "new"?

Update

This worked as suggested by matt:

cd C:\src\new
git remote add old ssh://git@..../old.git
git fetch old
git merge old/master --allow-unrelated-histories
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
  • Does this answer your question? [How to copy commits from one Git repo to another?](https://stackoverflow.com/questions/37471740/how-to-copy-commits-from-one-git-repo-to-another) – Liam Sep 18 '20 at 13:59

1 Answers1

3

Your local repo can have two remotes. You can pull/push with respect to each remote separately. So continue to work in old and every once in a while push to new as appropriate.

Typically you will appoint one person to do this. No one else needs to see new, and if no active development is happening in new yet, they probably should not.

(Of course the alternative is: don't even make new until you are ready to drop use of old.)

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    *Typically you will appoint one person to do this* or automate it using CI – Liam Sep 18 '20 at 14:01
  • 1
    @Liam Good point, CI is an excellent person to do this. :) – matt Sep 18 '20 at 14:03
  • Thanks matt. Do you have an example of how to configure this and how to switch between remotes? – Marcus Leon Sep 18 '20 at 14:11
  • Hi @MarcusLeon. You don't need to "switch". When you push a commit, you just specify the remote to push to. It's the difference between `git push old mybranch` and `git push new mybranch`. Having two remotes is a pretty common situation so there's lots of good info out there about it. – matt Sep 18 '20 at 14:20