一、Git的誕生:
很多人都知道,Linus在1991年創建了開源的Linux,從此,Linux系統不斷發展,已經成為最大的服務器系統軟件了,Linus雖然創建了Linux,但Linux的壯大是靠全世界熱心的志願者參與的,這么多人在世界各地為Linux編寫代碼,那Linux的代碼是如何管理的呢?事實是,在2002年以前,世界各地的志願者把源代碼文件通過diff的方式發給Linus,然后由Linus本人通過手工方式合並代碼!你也許會想,為什么Linus不把Linux代碼放到版本控制系統里呢?不是有CVS、SVN這些免費的版本控制系統嗎?因為Linus堅定地反對CVS和SVN,這些集中式的版本控制系統不但速度慢,且必須聯網才能使用。有一些商用的版本控制系統,雖然比CVS、SVN好用,但那是付費的,和Linux的開源精神不符,不過,到了2002年,Linux系統已經發展了十年了,代碼庫之大讓Linus很難繼續通過手工方式管理了,社區的弟兄們也對這種方式表達了強烈不滿,於是Linus選擇了一個商業的版本控制系統BitKeeper,BitKeeper的東家BitMover公司出於人道主義精神,授權Linux社區免費使用這個版本控制系統,安定團結的大好局面在2005年就被打破了,原因是Linux社區牛人聚集,不免沾染了一些梁山好漢的江湖習氣。開發Samba的Andrew試圖破解BitKeeper的協議(這么干的其實也不只他一個),被BitMover公司發現了(監控工作做得不錯!),於是BitMover公司怒了,要收回Linux社區的免費使用權,Linus可以向BitMover公司道個歉,保證以后嚴格管教弟兄們,嗯,這是不可能的。實際情況是這樣的:Linus花了兩周時間自己用C寫了一個分布式版本控制系統,這就是Git!一個月之內,Linux系統的源碼已經由Git管理了!牛是怎么定義的呢?大家可以體會一下,Git迅速成為最流行的分布式版本控制系統,尤其是2008年,GitHub網站上線了,它為開源項目免費提供Git存儲,無數開源項目開始遷移至GitHub,包括jQuery,PHP,Ruby等等。歷史就是這么偶然,如果不是當年BitMover公司威脅Linux社區,可能現在我們就沒有免費而超級好用的Git了。
2002年之前linux的開發者使用提交代碼之后使用diff命令進行代碼合並,在2002年之后有個商業版的版本控制軟件BitKeeper免費授權給linux使用,但是在2005年的時候samba的作者Andrew試圖破解BitKeeper的協議但是被監控發現了,於是Linus沒有道歉,而且花費兩周時間使用C語言重新編寫了一個分布式的版本控制系統,就是當前最牛的分布式版本控制系統Git。
Git在每個用戶都有一個完整的服務器,然后在有一個中央服務器,用戶可以先將代碼提交到本地,沒有網絡也可以先提交到本地,然后在有網絡的時候再提交到中央服務器,這樣就大大方便了開發者,而相比CVS和SVN都是集中式的版本控制系統,工作的時候需要先從中央服務器獲取最新的代碼,改完之后需要提交,如果是一個比較大的文件則需要足夠快的網絡才能快速提交完成,而使用分布式的版本控制系統,每個用戶都是一個完整的版本庫,即使沒有中央服務器也可以提交代碼或者回滾,最終再把改好的代碼提交至中央服務器進行合並即可。
關於分支:
master分支,進行發布的版本
dev 分支,也是測試的代碼分支,測試沒有問題之后合並到master
自己的分支
二、Git的安裝
mkdir /home/tools cd /home/tools/ wget https://bitnami.com/redirect/to/96764/bitnami-gitlab-8.5.1-0-linux-x64-installer.run chmod +x ./bitnami-gitlab-8.5.1-0-linux-x64-installer.run ./bitnami-gitlab-8.5.1-0-linux-x64-installer.run ---------------------------------------------------------------------------- Welcome to the Bitnami Gitlab Stack Setup Wizard. ---------------------------------------------------------------------------- Select the components you want to install; clear the components you do not want to install. Click Next when you are ready to continue. PhpPgAdmin [Y/n] :n GitLab : Y (Cannot be edited) Is the selection above correct? [Y/n]: y ---------------------------------------------------------------------------- Installation folder Please, choose a folder to install Bitnami Gitlab Stack Select a folder [/opt/gitlab-8.5.1-0]: /data/app/gitlab ---------------------------------------------------------------------------- Create Admin account Bitnami Gitlab Stack admin user creation Email Address [user@example.com]: chenxin@123.com Login [user]: chenxin #登陸時的用戶名 Password : #登陸時的密碼 Please confirm your password : Warning: The length of the password must be equal or greater than 8 Press [Enter] to continue: ---------------------------------------------------------------------------- Create Admin account Bitnami Gitlab Stack admin user creation Email Address [chenxin@123.com]: Login [chenxin]: Password : Please confirm your password : ---------------------------------------------------------------------------- Hostname that will be used to create internal URLs. If this value is incorrect, you may be unable to access your Gitlab installation from other computers. It is advisable to use a Domain instead of an IP address for compatibility with different browsers. Domain [127.0.0.1]: 172.16.1.100 Do you want to configure mail support? [y/N]: y ---------------------------------------------------------------------------- Configure SMTP Settings This is required so your application can send notifications via email. Default email provider: [1] GMail [2] Custom Please choose an option [1] : 2 ---------------------------------------------------------------------------- Configure SMTP Settings This data is stored in the application configuration files and may be visible to others. For this reason, it is recommended that you do not use your personal account credentials. Username []: chenxin@123.com #發送郵件的郵箱 Password : #郵箱的密碼 Re-enter : SMTP Host []: smtp.qiye.163.com SMTP Port [587]: 110 Secure connection [1] None [2] SSL [3] TLS Please choose an option [3] : 1 ---------------------------------------------------------------------------- Setup is now ready to begin installing Bitnami Gitlab Stack on your computer. Do you want to continue? [Y/n]: y ---------------------------------------------------------------------------- Please wait while Setup installs Bitnami Gitlab Stack on your computer. Installing 0% ______________ 50% ______________ 100% ######################################### ---------------------------------------------------------------------------- Setup has finished installing Bitnami Gitlab Stack on your computer. Info: To access the Bitnami Gitlab Stack, go to http://172.16.1.100:80 from your browser. Press [Enter] to continue
三、配置git服務
3.1 初始化配置
3.1.1 為了安全問題,首先去掉登陸頁面注冊賬戶的模塊,如下圖。
3.1.2 添加用戶,如下圖。
3.1.3 給用戶添加ssh keys密鑰認證,如下圖。
3.1.4 創建組,組里面可以有多個項目分支,可以將開發添加到組里面進行設置權限,不同的組就是公司不同的開發項目或者業務模塊,不同的組添加不同的開發即可實現對開發設置權限的管理。
3.1.5 創建項目
3.1.6 添加用戶到指定組中
四、配置客戶端
編輯~/.ssh/config文件,添加以下幾行: Host 172.16.17.100 User git Port 22 在本地已有的工程目錄下,將.git/config文件中的 url = git@sinosig101:root/<project_name>.git 改成 url = ssh://git@172.16.17.100/myweb/<project_name>.git 登錄http://172.16.17.100,用自己的用戶名/密碼登錄,初始用戶名為自己的姓名全拼,密碼與用戶名一致,但至少8位,不足8位補其123至8位,如: zhangsan/zhangsan lisi/sili360 加入自己的ssh-public-key即可