2014-08-28 122 views
2

改寫問題:如何將遠程git倉庫配置爲現有本地倉庫的新分支,其單個分支已鏈接到不同的遠程倉庫。將兩個git遠程倉庫配置爲兩個對應的本地分支

我有兩個git倉庫(項目)託管在兩個不同的網站(github和內聯網站點)。

它們彼此相似,因爲它們是從相同的基礎文件夾開始的。我想這兩個項目合併成一個單一的Git項目,使得

  • 本地分行的「主人」點GitHub庫的「主人」分支
  • 本地分支「intranet_branch」指向Intranet站點回購的「主人」分支

回答

2

看着以前的#1 question我想出了一個辦法來實現這個作爲follows

  • CD鏈接到GitHub庫本地文件夾

    cd ~/projects/prj_a 
    
  • 更新的.git/config來限制分支映射,使得當地的「主人」分支點到GitHub的「主人」分支

    [remote "origin"] 
    url = [email protected]:user/prj_a.git 
    fetch = +refs/heads/master:refs/remotes/origin/master 
    
  • 添加新的git遠程

    git remote add intranet [email protected]_server:user/intranet_project.git 
    
  • 更新的.git /配置,使得新的git遠程被取入新的遠程分支

    [remote "intranet"] 
    url = [email protected]_server:user/intranet_project.git 
    fetch = +refs/heads/master:refs/remotes/intranet/intranet_branch 
    
  • 來自新的遠程回購取分支

    git fetch intranet 
    
  • 結帳新的遠程的分支到一個新的地方分支。這也將切換到新分支。這是指向Github上

    git merge master 
    
  • 解決合併衝突,並承諾

  • 從intranet_branch推

    git checkout -b intranet_branch intranet/intranet_branch 
    
  • 合併主分支intranet_repo的主分支

    git push intranet intranet_branch 
    

再次測試一切

$ git checkout master 
     Switched to branch 'master' 
     Your branch is up-to-date with 'origin/master'. 
    $ git pull origin master 
     .... 
     * branch   master  -> FETCH_HEAD 
     Already up-to-date. 
    $ git push origin master 
     Everything up-to-date 
    $ git checkout intranet_branch 
     Switched to branch 'intranet_branch' 
     Your branch is up-to-date with 'intranet/intranet_branch'. 
    $ git pull intranet intranet_branch 
     ... 
     * branch   intranet_branch -> FETCH_HEAD 
     Already up-to-date. 
    $ git push intranet intranet_branch 
     Everything up-to-date