6

Can anyone help me with this,

My Folder structure is like this :

Repo1 [Repository]
 |- branch1 [branch]

Repo2 [Repository]
 |-branch1 [branch]

Now I need to merge file difference changes from Repo1/branch1 to Repo2/branch1

How do I do that. I am using git [bitbucket] as source control. For GUI I am using sourcetree

Thanks,

krutik

user3239408
  • 105
  • 1
  • 8
  • Mercurial and Git are two different systems. Make up your mind! ;) – Jan Krüger Jan 27 '14 at 09:47
  • Edited it sorry for that – user3239408 Jan 27 '14 at 10:11
  • Look here: http://stackoverflow.com/questions/244695/how-to-combine-two-branches-from-two-different-repositories-in-a-single-reposito – Maciej Oczko Jan 27 '14 at 10:39
  • I don't want to add branch from one repo to another instead I have two repository A and B both contain same source code but there are some updates made in repo A that I want to add in repo B. Please note they are two different repository with same branch not two branch in same repository – user3239408 Jan 27 '14 at 11:49
  • Yes, and the question that @MaciejOczko pointed you to covers that case. Add Repo1 as a remote in Repo2, fetch, and merge. – Magnus Bäck Jan 27 '14 at 14:10

1 Answers1

6

It's actually pretty easy if both "repos" are forks of the same repository. If they are truly different repositories completely, the merge gets a little messy, but is certainly possible.

The basic steps:

cd Repo2/branch1
git remote add Repo1 ../Repo1/branch1/.git
git fetch Repo1
git merge Repo1/branch1 --allow-unrelated-histories

That should trigger a regular "git merge" scenario. Even if both repos are actually 100% separate, Git will still do the merge, but won't be able to auto merge any differences between files.

Greg Burghardt
  • 17,900
  • 9
  • 49
  • 92
  • Doesn't this merge in the opposite direction than what the TO wants? – User Feb 09 '15 at 15:22
  • I suppose it does, however simply swap the "1"s for "2"s in the repository and branch names and you get what the question wants. The pattern is exactly the same. – Greg Burghardt Feb 09 '15 at 16:29
  • I had to add `--allow-unrelated-histories` to my git command to make it work. – Holly Cummins Nov 16 '21 at 21:36
  • @HollyCummins: updated my answer. When I originally wrote this answer, I don't remember needing that flag. I may have simply forgot, or Git changed a default setting in the 6 years since I posted this. Thanks! – Greg Burghardt Nov 17 '21 at 13:09
  • Thanks, @GregBurghardt. I think it's a change in git behaviour, not your forgetfulness! – Holly Cummins Nov 18 '21 at 14:24