2017-10-11 71 views
1

我想從GitHub克隆一個開源項目,但我想使用Bitbucket作爲遠程存儲庫主機,因爲它的私有倉庫是免費的。如何從GitHub複製項目,但使用Bitbucket作爲遠程存儲庫

我不打算fork/pull請求,但是當原始項目得到更新時,我想將更新拉到我的本地存儲庫併合並。

我想最終我需要兩個遠程存儲庫。 (來源和上游?)

什麼是建立這樣的環境的正確/最安全的方法?

+2

我想你已經描述了一個合適的解決方案。你需要兩個遙控器,一個指向gitub,一個指向bitbucket。名稱'origin'和'upstream'對於這種設置非常典型。首次推送分支時,請確保使用'-u'設置正確的遠程追蹤分支。 – larsks

+0

謝謝,很高興知道我正處在一個正確的方向。我只知道git的基本命令,從來沒有在這個級別嘗試過任何東西。我已閱讀過許多博客文章和文章,但找不到完全相同的情況。 –

回答

1

我剛剛在GitHub上測試了一個項目:google-calendar-backup

首先,我登錄到我的Bitbucket帳戶並創建了一個名爲google-calendar-backup的私人Git回購協議。

然後,我做了以下步驟:
(注:我在Windows上,這樣的路徑可能是您的機器上的不同)

  1. 克隆原來從GitHub

    回購
    git clone https://github.com/christianspecht/google-calendar-backup C:\LocalDir 
    
  2. 這將在本地repo中創建一個指向GitHub的遠程「origin」。
    既然你想主要使用Bitbucket,Bitbucket應該是「主」遠程origin,所以我們將重命名現有的。

    cd c:\localdir 
    git remote rename origin upstream 
    
  3. 轉到本地目錄,並添加到位桶回購作爲第二遙控:

    git remote add origin https://bitbucket.org/christianspecht/google-calendar-backup 
    
  4. (可選)同時顯示遙控器:

    git remote -v 
    

    在我的機器,我得到這個結果:

    origin https://bitbucket.org/christianspecht/google-calendar-backup (fetch) 
    origin https://bitbucket.org/christianspecht/google-calendar-backup (push) 
    upstream  https://github.com/christianspecht/google-calendar-backup (fetch) 
    upstream  https://github.com/christianspecht/google-calendar-backup (push) 
    
  5. 按各分公司到位桶一旦

    git push -u --all origin 
    

    結果:

    Username for 'https://bitbucket.org': christianspecht 
    Password for 'https://[email protected]': 
    Counting objects: 30, done. 
    Delta compression using up to 4 threads. 
    Compressing objects: 100% (30/30), done. 
    Writing objects: 100% (30/30), 4.41 KiB | 0 bytes/s, done. 
    Total 30 (delta 12), reused 0 (delta 0) 
    To https://bitbucket.org/christianspecht/google-calendar-backup 
    * [new branch]  master -> master 
    Branch master set up to track remote branch master from origin. 
    

    (感謝larsks-u - 我不知道這一點,我還在學習的Git自己)


就是這樣。現在您可以進行更改並推送至origin(Bitbucket)。
偶爾,您需要從upstream(GitHub)取得原始項目的新更改。

+0

謝謝,它工作完美。我也需要以同樣的方式設置另一臺計算機。但是因爲我已經將代碼推送到Bitbucket存儲庫,所以我想在Github上克隆這個代碼而不是原始代碼,然後在Github庫中添加一個上游分支。我明天再試。 –

相關問題