Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge between two local repositories

Tags:

git

git-merge

I have two local git repositories (one is a clone of master repo, other is a clone of fork of master). Is there a way to merge a branch of one with the same branch from other?

Note - I can't just add the master as upstream , because we have some issues that way currently - git fetch fails due to pack-object failure .

like image 406
nikel Avatar asked Jan 26 '14 05:01

nikel


People also ask

Can we merge two different repositories?

To combine two separate Git repositories into one, add the repository to merge in as a remote to the repository to merge into. Then, combine their histories by merging while using the --allow-unrelated-histories command line option.

How do I merge two GitHub 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.


1 Answers

You could add another remote repository such as 'local'.

Try the following way (which I just ran successfully):

(Suppose your local repositories are MyGitRepo.git and AnotherRepo.git in the same folder)

in MyGitRepo.git folder:

$: git remote add local ../AnotherRepo
$: git fetch local
$: git merge local/master

If master is the branch you want to merge.

After git fetch local, you will probably see the following:

$ git fetch local
From ../AnotherRepo
 * [new branch]      master     -> local/master

which means that another tracking branch is successfully made to track the (other) local repository.

Ref: read this link about multiple remote repositories

like image 152
J Jiang Avatar answered Oct 14 '22 01:10

J Jiang