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