1

I have found a few similar topics but please take a look at my solution. It looks like git subtree is intended to solve a slightly different problem. I have two repositories A and B. Repo B has only one directory which is unrelated with the repo A content. I only want to add that directory to repo A and have one consistent history in repoA. Repo B will not be used anymore.

Here are steps:

cd RepoB
git checkout develop
git remote set-url origin RepoA
git pull origin develop
git push -u origin develop

git pull will performed merge, should I use fetch and then merge with some option parameter ?

Do you have some other suggestions ?

Irbis
  • 11,537
  • 6
  • 39
  • 68
  • Possible duplicate of [Merge two Git repositories without breaking file history](https://stackoverflow.com/questions/13040958/merge-two-git-repositories-without-breaking-file-history) – Peter Reid Jun 22 '17 at 09:28
  • What does "one consistent history" mean here? Do you need to preserve the history of changes to both A and B? Does the history have to accurately reflect that this change was made to A before this change to B, but this change to B before this other change to A, etc.? – Mark Adelsberger Jun 22 '17 at 13:29

1 Answers1

1

You can try to rebase RepoB ontop of RepoA:

repoA/master:  A--B--C--D
repoB/master:  X--Y--Z

Result: A--B--C--D--X--Y--Z

by running

cd repoA
git remote add repoB git@server:repoB
git fetch repoB
git checkout repoB/master  # replace branch name if needed
git rebase master  # replace branch name if needed
Nils Werner
  • 34,832
  • 7
  • 76
  • 98