Search code examples
gitversion-controlrepository

Move GIT including their branchs and tags from A to B


I have a project that use 2 different git. Both of them are the same app and what different it is a version & language. Consider Folder_1 directory is Version_1 project and Folder_2 directory is Version_2 project.

Explanation:

  • In Folder_1, I use C language.
  • And in Folder_2 I use C# language

Directory:

|-- Local Disk (D:)
    |-- Folder_1 (D:\Folder_1)
    |-- Folder_2 (D:\Folder_2)

Folder_1 git structure:

Init --- Branch1 --- Dev
   \--- Branch2 --- Master

Folder_2 git structure:

Init --- Dev
   \--- BranchX --- Master
    \--- Test

QUESTION:

  1. How do I combine or copy or move Folder_1 git structure into Folder_2 git?

Desired output:

Init --- Dev
  \--- BranchX --- Master
   \-- Test
    \- v1_Init
            \--- v1_Branch1 --- v1_Dev
             \-- v1_Branch2 --- Version_1
  1. It is a bad practice of doing that? & If the answer is yes, could explain why..

Solution

  • To make one Git repo that has branches with unrelated histories all you have to do is "fetch" the objects and create the "refs".

    cd repo2
    git remote add repo1 /path/to/repo1
    git fetch repo1
    git branch v1_Dev repo1/Dev
    git branch v1_Master repo1/Master
    

    Now you can switch between the two projects just by switching branch:

    git checkout v1_Master
    git checkout master