多人寫作項目中, 需要建立一個主分支, 將可發佈的代碼提交進來。 日常開發, 個人的代碼提交到個人的分支。
1. 在git server 上, 在一個repository中, 可以fork出個人分支, 就是我們自己的workspace
一. 建立本地工作環境
a. 初始化本地環境
>git init
b. git remote 關聯遠程倉庫, 注:自主建立工作目錄,不使用clone,屬於腦洞大開型,有可能導致本地和遠程出現不同步的地方,比如先在本地加入一個文件
>git remote add ly https://github.com/lianghyan/hope.git
刪除一個遠程倉庫關聯
>git remote rm ly
c. 本地沒有下載工程的情況下, 自以爲是的加入了一些file
>git add hello.txt
d.從遠程下載分支到本地
>git pull ly master --alow-unrelated-histories
取得遠程倉庫ly所有的結構信息
>git fetch ly
取得遠程倉庫ly的分支master的信息
>git fetch ly master
e. 提交本地的文件到遠程server
>git push -u ly master
二. 將主分支的改動同步到個人分支
1.將本地的project關聯到遠程的主分支和個人分支
>git remote add mainhope https://github.com/blue/hope.git
>git remote add subhope https://github.com/subblue/hope.git
首先將遠程主分支同步到本地
>git pull mainhope dev
將本地的推送到遠程個人分支
>git push subhope dev
>git push ply dev