20

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 .

Community
  • 1
  • 1
nikel
  • 3,402
  • 11
  • 45
  • 71

1 Answers1

42

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

Community
  • 1
  • 1
J Jiang
  • 1,452
  • 10
  • 14
  • this was easy :) , should have given it a try – nikel Jan 26 '14 at 06:46
  • Note that using relative paths (like the example here shows) is pretty broken under git-for-windows. I had to use absolute paths. – Fake Name Jun 22 '18 at 01:29
  • 6
    Thanks: if you also face `fatal: refusing to merge unrelated histories` -> add `--allow-unrelated-histories` for more information check: https://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories-on-rebase – Fabian Apr 26 '19 at 12:55
  • This procedure adds ../AnotherRepo as a permanent repository of MyGitRepo.git so maybe, after merging both repositiores we might want to delete the ../AnotherRepo reference from MyGitRepo.git. – Krauss Oct 21 '20 at 08:38