工程A和工程B完全不同,可以作為兩個分支放到git中嗎?
可以的。
下面以github page為例:
octopress是一個博客系統,它可以生成一個博客。
但是github page約定,這個生成的博客,必須放到username.github.io這個repository的master分支中才能作為博客訪問。
因此,我們就需要再建一個分支,把octopress放到這個分支上。
而把octopress生成的博客放到master分支上。
(1)github中建立username.github.io這個repository
(2)克隆到本地
$ git clone https://github.com/thzt/thzt.github.io.git
注:
這時候還是一個分支
$ git branch
> * master
(3)創建orphan分支,名為source
$ git checkout --orphan source
注:
如果不提交東西,這個分支實際上沒有創建
(3)修改一些東西,并提交
$ git add .
$ git commit -m "init"
$ git push origin source
注:
git push origin source表示把本地代碼(origin)提交到source分支
git push origin master表示把本地代碼(origin)提交到master分支
(4)現在就有兩個分支了master和source
切換到master分支
$ git checkout master
切換到source分支
$ git checkout source
注:
用checkout切換分支時,本地文件系統會瞬間發生變化。