Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging two remote repositories in Git

Tags:

git

git-merge

I want to merge two remote repositories in Git.

One is mainstream repository, which I do not have write permission. I want to track its master branch.

The other is maintained by us, I have full rights on it.

I want to track the mainstream code. At the same time, our modification would be recorded in my remote repository.

How do I do this?

like image 585
Readon Shaw Avatar asked Nov 20 '09 02:11

Readon Shaw


People also ask

Can you merge two repos?

If you actually want to merge both repos, this step is unnecessary. $ git rm -rf * $ git commit -m "Delete all the things." Merge master-holder into master. (If you didn't do the delete step above, you have to option of git checkout master-holder; git rebase master instead.)

How do I merge two git repository branches?

Merging Branches in a Local Repository To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch.

Can a git repo have two remotes?

You can add multiple remotes by using git remote or git config commands or editing the config file. As git can group multiple remotes, you can follow any of the following ways to configure multiple remotes to push simultaneously(no need all). You can set multiple remote URLs to a single remote using git remote.


1 Answers

I would recommend:

  • cloning yourRemoteRepo (that way, you can easily pull/push from that repo)
  • adding mainstreamRepo as a remote and fetch its branch, then track the one which interest you

    git clone git://yourRemoteRepo git remote add mainStreamRepo http://mainStreamRepo git fetch mainStreamRepo git checkout -b mainStreamMaster mainStreamRepo/master git checkout master 

From there, you can

  • merge mainStreamMaster to your master,
  • or rebase your master on top of mainStreamMaster (in order to integrate the full history of mainStreamMaster into your master branch)
  • then make some evolutions to master (or to a topic-specific branch) that you can push to yourRemoteRepo.
like image 114
VonC Avatar answered Sep 29 '22 09:09

VonC