1、准備相關軟件
1.1 准備ssh必要工具
方便登錄和進行ssh認證:
1 $ sudo apt-get install openssh-client 2 $ sudo apt-get install openssh-server
1.2 准備必要的git工具
注意建立專用用戶進行控制,比如后面的兩條命令:
1 $ sudo apt-get install git git-core 2 $ sudo useradd git 3 $ sudo passwd git
2、 創建服務器端的空白倉庫
1 $ mkdir -p gitRepo/project.git #創建必要項目文件夾 2 $ git --bare init gitRepo/project.git # 初始化空白倉庫
3、 客戶端初始化倉庫和提交代碼
$ cd project $ git init $ git add . $ git commit -am "init the repo" $ git remote add origin user@ip:/path/to/project.git #設置遠程倉庫路徑 $ git push origin master #提交第一版代碼了;
注意:如果設置的遠程庫路徑有問題,可以通過git config 命令來修正,比如:
1 $ git config remote.origin.url #查看當前設置的路徑 2 $ git config remote.origin.url user@ip:/path/to/project.git #修改當前路徑為后者
4、 開始協作
其他用戶可以通過直接git clone的方式進行合作了,比如:
$ git clone user@ip:/path/to/project.git local_project_name
更多git使用方法參考git help;