-1

I'm trying to reorganize my code directory and merge two unrelated Git repos. Both repos are local.

I found a similar question here: How do you merge two Git repositories?

...but the solution didn't work for me. I asked in the comments sections about this and another user suggested I ask my question as a separate question.

I created a test/sandbox environment to test resolving this Git merge problem. My set up is:

/home/dir01/merge_repos  # this is the sandbox dir
|
/home/dir01/merge_repos/old_dir_01/old_repo # git init was done here; .git directory exists here

/home/dir01/merge_repos/old_dir_01/old_repo/source_file_01.py
/home/dir01/merge_repos/old_dir_01/old_repo/source_file_01.py
|
/home/dir01/merge_repos/new_repo  # git init was also done here.

I want to merge the files in old_repo with the Git repo in new_repo.

As per the solution offered in the original question, I did the following:

  1. I created a dummy file under new_repo, then did a git add and git commit of this dummy file.

  2. While in the new_repo/ directory, I issued > git remote add old_repo /home/dir01/merge_repos/old_dir_01/old_repo

  3. git fetch old_repo --tags

  4. git merge --allow-unrelated-histories old_repo/master

At Step 4, Git complains that --allow-unrelated-histories is an unknown option.

So I tried a git merge without the --allow-unrelated-histories option. This didn't work; Git complained with fatal: old_repo/master - not something we can merge.

My question is, can I do a Git merge of two unrelated Git repos using a Git version that is older than v2.9?

I'm using Git v1.8.3.1.

matt
  • 515,959
  • 87
  • 875
  • 1,141
SQA777
  • 352
  • 5
  • 15
  • 3
    “I'm using GIT v 1.8.3.1” Ok, so may one ask why? Git 2.9 was five years ago. Five years! That’s a lifetime in computer terms. We’re up to what, 2.31 now? – matt Apr 11 '21 at 02:42
  • 1
    I would actually recommend trying something like [this](https://stackoverflow.com/a/2949855/421195): `# in proj2: git remote add proj1 path/to/proj1; git fetch proj1; git merge proj1/master # or whichever branch you want to merge`, And yes, you should *definitely* upgrade your Git to 2.25 or higher – paulsm4 Apr 11 '21 at 02:44
  • 1
    NB: Security vulnerabilities ..... https://github.blog/2019-12-10-multiple-git-vulnerabilities-in-2-24-and-older/. Also read: https://serverfault.com/questions/709433/install-a-newer-version-of-git-on-centos-7 – Stephen C Apr 11 '21 at 02:46
  • @matt, I used the one that came with Centos v7.7. Found no need to upgrade GIT until perhaps now. – SQA777 Apr 11 '21 at 02:47
  • 1) Read the threads in my link to resolve your problem. 2) Upgrade your Git ... because you need to :) PS: Centos 7 is over 6 years old - it's unsurprising it has a lot of obsolete packages. – paulsm4 Apr 11 '21 at 02:48
  • @paulsm4, it seems that the only difference between what I did and what you recommend is that I do not use the "--tags" option in the 'git fetch' command. Is this correct? – SQA777 Apr 11 '21 at 02:49
  • Also please stop saying GIT. It’s called Git. – matt Apr 11 '21 at 05:46
  • @matt is like when java script is used instead of JavaScript. “It’s one word!! ” – evolutionxbox Apr 11 '21 at 10:38

1 Answers1

0

To follow up on my original question, NO, you don't need a certain version of Git to do a Git merge.

For Git versions that are v2.9 or later, Git provides the --allow-unrelated-histories option. So you do it as answered here: How do you merge two Git repositories?

cd path/to/project-b
git remote add project-a /path/to/project-a
git fetch project-a --tags
git merge --allow-unrelated-histories project-a/master 
git remote remove project-a

For Git versions that do not support the --allow-unrelated-histories option, you can still do a Git merge but a bit differently.

cd path/to/project-b
git remote add project-a /path/to/project-a
git fetch project-a # Don't use the --tags option
git merge project-a/master # Don't use the --allow-unrelated-histories option
git remote remove project-a

Thanks to @paulsm4 for the answer.

SQA777
  • 352
  • 5
  • 15