http://www.cnblogs.com/zhcncn/p/4030078.html
http://www.th7.cn/system/lin/201407/64759.shtml
http://www.pythoner.com/263.html
1. 安裝Git
1.1 Ubuntu12.04下可以使用apt-get方式安裝,也可以下載源代碼安裝【1】,我們這裏使用apt-git安裝。
但由於直接使用 sudo apt-get install git 安裝的版本較老,因此我們參考【2】中給出的PPA源。
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git
安裝完成後,檢查是否安裝成功
git --version
顯示 git version 2.1.1,表明安裝成功。
2. 設置Git
(1)設置用戶名和email。
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
此時,Home目錄下會新建一個.gitconfig文件
3. 爲GitHub賬號添加SSH Keys
以公鑰認證方式訪問SSH協議的Git服務器時無需輸入口令,而且更安全。(訪問HTTP協議的Git服務器時,比如提交修改,每次都需要輸入口令。)
(1)創建SSH key
$ ssh-keygen -t rsa -C "[email protected]"
系統會提示key的保存位置(一般是~/.ssh目錄)和指定口令,保持默認,連續三次回車即可。
(2)Copy SSH Key
然後用vim打開該文件,id_rsa.pub文件內的內容,粘帖到github帳號管理的添加SSH key界面中。
vim ~/.ssh/id_rsa.pub
(3)添加到GitHub
登錄github-> Accounting settings圖標-> SSH key-> Add SSH key-> 填寫SSH key的名稱(可以起一個自己容易區分的),然後將拷貝的~/.ssh/id_rsa.pub文件內容粘帖-> add key”按鈕添加。
(4)測試
ssh -T [email protected]
4. 爲GitHub上的Repository提交修改
(1)git clone已存在GitHub上的Repository。(在新建的~/MyTestFolder目錄中)
git clone https://github.com/zhchnchn/ZhchnchnTest.git
(2)修改一個文件,然後提交
vim README.md
git status
git add README.md
git status
git commit -m "Edit by WorkUbuntu 1204"
git status
git remote add origin https://github.com/zhchnchn/ZhchnchnTest.git
這時會報錯誤:
fatal: remote origin already exists.
解決辦法【3】:
$ git remote rm origin
然後再次執行 git remote add origin https://github.com/zhchnchn/ZhchnchnTest.git
(3)之後,需要將修改push到GitHub上
git push -u origin master
執行該條命令後,會要求輸入GitHub賬戶的用戶名和密碼。
(4)提交完成後,查看GitHub上的Repository,會發現內容修改成功。