Joe C
Joe C

Reputation: 2834

Rebase git repo from different repo

I need to rebase my git repo from a different repo. And not add the different repo as a subtree. The different repo has changes to the same files I'm working on in my local repo. (Don't ask why we don't just unite the repos into different branches in one repo [politics].)

My repo and the common repo respectively.

a-b-c-d

a-b-c-w-x-y-z

My repo needs to become

a-b-c-w-x-y-z-d

Remember it's a different repo not just a different branch. The strategy I was pursuing was to add a branch to my repo from the common repo via these command

remote add common-repo ssh:/path/to/common/repo

Then I see the common repo in my "git remote -v" command. But I don't see it in my "git branch -v" command. If I could just get that into a branch, do the rebase/merge, then remove the branch or never push the branch, then I be rebasing my repo from that common repo.

Of course I want my own repo to retain all the history that the common repo had, noit a collapsed merge.

Upvotes: 2

Views: 3270

Answers (3)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42869

I assume there's a common parent, since you used some letters twice, I think you can achieve that by adding the second repo as a different remote

git remote add second_origin URL

then fetch the second remote

git fetch second_origin

then do the rebase

#assuming you are on origin/master
git rebase second_origin/master master

I'm not sure this will work, but for me it seems logically correct, and keep in mind if the whole rebase goes crazy and you find your self stuck, you can always run git rebase --abort

Upvotes: 3

Adam Dymitruk
Adam Dymitruk

Reputation: 129654

I'm assuming that commits a, b and c are the same but not identical. In this case you just fetch from the other repo

git fetch otherrepo

then you rebase your work onto the last common part, c

git rebase --onto otherrepo/c ^myrepo/d myrepo/d

since it's one commit, in this case a cherry-pick would do

git checkout otherrepo/c
git cherry-pick myrepo/d

Substitute the repo/commit markers with branches you create to represent them. The above will be easier to deal with that way.

If you are going to work with this other repo in this manner, I would suggest you merge and turn on rerere as you will never be able to publish your merges and the merges on your side will get more and more complicated. Rerere will allow you to do this fast as any conflict resolutions will be remembered in the future.

Upvotes: 0

elmart
elmart

Reputation: 2374

To see remote branches, you should use one of this:

git branch -a
git branch -r

instead of

git branch -v

Once you can see, for example, branch remotes/origin/master, then, to rebase your master branch on top of that you should just do:

git checkout master
git rebase origin/master

Upvotes: 1

Related Questions