Merge no common commits into master branch?

m00nbeam360.0 picture m00nbeam360.0 · Oct 16, 2015 · Viewed 12.2k times · Source

I have a Git repo that has a lot of commits and separate code, say

/Proj1

I also have another Git repo that has 1 commit in it that is not a common commit,

/Proj2

How can I merge the two repos and have history show up correctly with parent commits? Basically, there aren't any shared commits between the two repos but I want to have one repo that has both sets of code. I'd like for it to look like:

proj2 commit
proj2 commit
proj1 commit (root)

I know that rebase is an option, but not sure if using --onto replaces the root commit (which it seems to do if I do a fetch from the remote repo and rebase --onto --root master).

I've tried using git subtrees which initially look like they work, but when I use git-tfs to push my commits up, but I'm getting an error that says

warning: the parent ... does not belong to a TFS tracked branch (not checked in TFS) and will be ignored

and the commits don't actually push up (also likely because it's a subtree).

Edit: I only want to end up with 1 repo (Proj1) but have Proj2's commits come after Proj1's commit on the master branch.

Answer

m00nbeam360.0 picture m00nbeam360.0 · Oct 16, 2015

Cupcake helped solve this one. Here's one way to do this:

In ProjA, add Proj B as a remote:

git remote add projb C:\projB

Do a git fetch to grab all of the commits of projB's master branch:

git fetch projb

Rebase starting from the root of projB onto the tip (end) of projA's master branch:

git rebase --onto master --root projb/master

And that's it! There are potentially less risky ways to perform this, but this definitely solves it for now.