轉載自http://git-scm.com/book/zh-tw/%E4%BC%BA%E6%9C%8D%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E6%9E%B6%E8%A8%AD%E4%BC%BA%E6%9C%8D%E5%99%A8
轉載自http://stackoverflow.com/questions/8006393/force-add-despite-the-gitignore-file
架設伺服器
首先,創建一個名為 'git' 的用戶
$ sudo adduser git
現在可以用 --bare
選項運行 git init
來建立一個裸倉庫,這會初始化一個不包含工作目錄的倉庫。
$ cd ~ (如果現在打pwd,應該是在/home/git) $ mkdir project.git $ cd project.git $ git --bare init
這時,Join,Josie 或者 Jessica 就可以把它加為遠端倉庫,推送一個分支,從而把第一個版本的專案檔案上傳到倉庫裡了。值得注意的是,每次添加一個新專案都需要通過 shell 登入主機並創建一個裸倉庫目錄。我們不妨以 gitserver
作為 git
用戶及項目倉庫所在的主機名稱。如果在網路內部運行該主機,並在 DNS 中設定 gitserver
指向該主機,那麼以下這些命令都是可用的:
# 在 John 的電腦上 $ cd myproject $ git init $ git add -f . $ git commit -m 'initial commit' $ git remote add origin git@gitserver:/opt/git/project.git $ git push origin master
NOTE:
Force add the .gitignore file
See man git add
:
-f, --force
Allow adding otherwise ignored files.
這樣,其他人的克隆和推送也一樣變得很簡單:
$ git clone git@gitserver:/opt/git/project.git