Git搭建團隊開發環境操作演練
模擬創建遠程git倉庫
1.首先創建如下目錄結構:
/Users/hujh/Desktop/GitTest2/GitServer/weibo
weibo是我們要創建的項目
2.切換目錄
$ cd /Users/hujh/Desktop/GitTest2/GitServer/weibo
3. 建立空白代碼庫(專門用于團隊開發)
$ git init —bare
正常一般能顯示類似如下結果代表初始化空倉庫成功
Initialized empty Git repository in /Users/hujh/Desktop/Git演練/GitServer/weibo/
項目經理初始化本地倉庫
1.項目經理創建如下目錄結構:
/Users/hujh/Desktop/GitTest2/Manager
2.切換目錄
$ cd /Users/hujh/Desktop/GitTest2/Manager/weibo
3.”克隆"代碼庫到本地
$ git clone /Users/hujh/Desktop/GitTest2/GitServer/weibo/
顯示提示結果如下:
Cloning into 'weibo'...
warning: You appear to have cloned an empty repository.
done.
代表克隆倉庫成功,您可以進入weibo目錄通過
ls -la查看到如下圖結果:
有一個.git目錄,這就是倉庫的隱藏目錄。
4.個人信息配置(因為要演示一臺機器上的多人協作,日常開發可以忽略)
$ git config user.name manager
$ git config user.email manager@163.com
5.添加.gitignore文件指定哪些文件不納入版本庫的管理
參考網址: https://github.com/github/gitignore
1)在.git目錄的同級目錄中將如下命令粘貼執行
echo -e "# Xcode
#
build/
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Pods/" > .gitignore
2)通過ls -la查看,可以看到生成了一個.gitignore文件
3)執行如下命令,將.gitignore添加到代碼庫
$ git add .gitignore
$ git commit .gitignore -m “添加.gitignore忽略文件"
6.創建初始化項目
利用Xcode在weibo目錄下創建項目,注意當我們選擇保存地址進入weibo目錄時,Create Git repository 選項卡編程灰色了。
編寫和修改代碼后,選擇Source Control ——->Commit 提交我們的代碼:
在彈出的界面中進行操作,參考圖中說明:
上圖中我沒有選擇自動推送,在項目開發中為了節約時間,可以勾選此項,這里不勾選是為了告訴大家如何手動推送:選擇SourceControl ——> push
然后點擊push
如果推送成功,會顯示push successful,這就代表推送到遠程倉庫成功。
至此,項目經理初始化項目倉庫就完成了。
員工jackie著手繼續開發項目
- 創建員工jackie目錄
/Users/hujh/Desktop/GitTest2/jackie
2.進入員工jackie的目錄
cd /Users/hujh/Desktop/GitTest2/jackie
3.”克隆"代碼庫到本地
$ git clone /Users/hujh/Desktop/GitTest2/GitServer/weibo/
就可以在jackie目錄下看到項目文件了
然后就可以開發項目了。