Importing one git repo as a branch into another git repo

前端 未结 3 676
予麋鹿
予麋鹿 2021-02-01 21:20

For historic reason we have source code for different version in different git repositories. So while Project A holds the version X of the source Project B holds version Y of th

相关标签:
3条回答
  • 2021-02-01 21:39

    I am not sure, what you mean by "git project". In git the states of source code are described by commits (a.k.a. revisions). These are stored in repositories, but are independent of the them and can be copied between repositories freely. In fact, to work on the sources git always copies the commits to your local repository that lives in the .git directory of your working copy. Branches are just names pointing to commits.

    So if you have some branches in one repository and other branches in another repository, you can:

    1. Pull both into your local working repository:

      git remote add B git://url.to/project.B.git
      git fetch B
      
    2. Base your work on branches from B

      git checkout -b newname remotes/B/branchname
      
    3. Push the branches you got from one central repository to the other:

      git push origin remotes/B/branchname:branchname
      

      or the other way around

      git push B remotes/origin/master:othername
      

    You can omit the remotes/ prefix most of the time.

    0 讨论(0)
  • 2021-02-01 21:44

    This is simple with Git. You have to add project B as remote, then fetch:

    git remote add projectB git://url.to/projectB.git
    git fetch projectB
    
    0 讨论(0)
  • 2021-02-01 21:47
    1. First clone project A from git hub

    git clone {git hub Project A URL}

    1. Add remote repository path of project B

    git remote add projectBrepo {git hub project B URL}

    1. project B branches will be fetched

    git fetch projectBrepo

    1. check the all branches from project A and project B

    git branch -v -a

    1. check-out each branch name from project B (ex:master, branch_name1)

    git checkout -b master_old remotes/projectBrepo/master

    1. Push the master branch from project B to project A as master_old

    git push origin master_old

    1. check-out branch_name1 from project B

    git checkout -b branch_name1 remotes/projectBrepo/branch_name1

    1. Push the brnach_name1 from project B to project A

    git push origin branch_name1

    0 讨论(0)
提交回复
热议问题