How to merge between two local repositories

10,117

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

Share:
10,117

Related videos on Youtube

nikel
Author by

nikel

Another guy who like programming:P...B.Tech,Computer Science.I believe that Programming is the art of making perfect things.

Updated on September 16, 2022

Comments

  • nikel
    nikel over 1 year

    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 .

  • nikel
    nikel over 10 years
    this was easy :) , should have given it a try
  • J Jiang
    J Jiang over 10 years
    @nikel glad it helps. :)
  • Fake Name
    Fake Name almost 6 years
    Note that using relative paths (like the example here shows) is pretty broken under git-for-windows. I had to use absolute paths.
  • Fabian
    Fabian about 5 years
    Thanks: if you also face fatal: refusing to merge unrelated histories -> add --allow-unrelated-histories for more information check: stackoverflow.com/questions/37937984/…
  • Krauss
    Krauss over 3 years
    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.