Linux下使用git命令及github項目


在linux下搭建git環境
1、創建Github賬號,https://github.com
2、Linux創建SSH密鑰:
  1. ssh-keygen  ##一直默認就可以了  
ssh-keygen  ##一直默認就可以了
3、將公鑰加入到Github賬戶信息Account Settings->SSH Key
4、測試驗證是否成功。
  1. ssh -T [email protected]  
  2. Hi someone! You've successfully authenticated, but GitHub does not provide shell access.  
ssh -T [email protected]
Hi someone! You've successfully authenticated, but GitHub does not provide shell access.

同步github到本地
1、複製項目到本地:
  1. git clone git://github.com:xxxx/test.git ##以gitreadonly方式克隆到本地,只可以讀  
  2. git clone [email protected]:xxx/test.git  ##以SSH方式克隆到本地,可以讀寫  
  3. git clone https://github.com/xxx/test.git ##以https方式克隆到本地,可以讀寫  
  4. git fetch [email protected]:xxx/xxx.git  ##獲取到本地但不合並  
  5. git pull [email protected]:xxx/xxx.git ##獲取併合並內容到本地  
git clone git://github.com:xxxx/test.git ##以gitreadonly方式克隆到本地,只可以讀
git clone [email protected]:xxx/test.git  ##以SSH方式克隆到本地,可以讀寫
git clone https://github.com/xxx/test.git ##以https方式克隆到本地,可以讀寫
git fetch [email protected]:xxx/xxx.git  ##獲取到本地但不合並
git pull [email protected]:xxx/xxx.git ##獲取併合並內容到本地

本地提交項目到github
1、本地配置
  1. git config --global user.name 'onovps'  
  2. git config --global user.email '[email protected]' #全局聯繫方式,可選  
git config --global user.name 'onovps'
git config --global user.email '[email protected]' #全局聯繫方式,可選
2、新建Git項目並提交到Github。
  1. mkdir testdir & cd testdir  
  2. touch README.md  
  3. git init #初始化一個本地庫  
  4. git add README.md #添加文件到本地倉庫  
  5. git rm README.md #本地倒庫內刪除  
  6. git commit -m "first commit" #提交到本地庫並備註,此時變更仍在本地。  
  7. git commit -a  ##自動更新變化的文件,a可以理解爲auto  
  8. git remote add xxx [email protected]:xxx/xxx.git  #增加一個遠程服務器的別名。  
  9. git remote rm xxx   ##刪除遠程版本庫的別名  
  10. git push -u remotename master #將本地文件提交到Github的remoname版本庫中。此時才更新了本地變更到github服務上。  
mkdir testdir & cd testdir
touch README.md
git init #初始化一個本地庫
git add README.md #添加文件到本地倉庫
git rm README.md #本地倒庫內刪除
git commit -m "first commit" #提交到本地庫並備註,此時變更仍在本地。
git commit -a  ##自動更新變化的文件,a可以理解爲auto
git remote add xxx [email protected]:xxx/xxx.git  #增加一個遠程服務器的別名。
git remote rm xxx   ##刪除遠程版本庫的別名
git push -u remotename master #將本地文件提交到Github的remoname版本庫中。此時才更新了本地變更到github服務上。

分支版本操作
1、創建和合並分支
  1. git branch #顯示當前分支是master  
  2. git branch new-feature  #創建分支  
  3. git checkout new-feature  #切換到新分支  
  4. vi page_cache.inc.php  
  5. git add page_cache.inc.php  
  6. git commit -a -m "added initial version of page cache"  
  7. git push origin new-feature  ##把分支提交到遠程服務器,只是把分支結構和內容提交到遠程,並沒有發生和主幹的合併行爲。  
git branch #顯示當前分支是master
git branch new-feature  #創建分支
git checkout new-feature  #切換到新分支
vi page_cache.inc.php
git add page_cache.inc.php
git commit -a -m "added initial version of page cache"
git push origin new-feature  ##把分支提交到遠程服務器,只是把分支結構和內容提交到遠程,並沒有發生和主幹的合併行爲。
2、如果new-feature分支成熟了,覺得有必要合併進master
  1. git checkout master  #切換到新主幹  
  2. git merge new-feature  ##把分支合併到主幹  
  3. git branch #顯示當前分支是master  
  4. git push  #此時主幹中也合併了new-feature的代碼  
git checkout master  #切換到新主幹
git merge new-feature  ##把分支合併到主幹
git branch #顯示當前分支是master
git push  #此時主幹中也合併了new-feature的代碼

git命令使用思維圖:【非常有料

http://www.cnblogs.com/1-2-3/archive/2010/07/18/Git-commands.html

轉自:http://blog.csdn.net/five3/article/details/8904635

發佈了17 篇原創文章 · 獲贊 33 · 訪問量 20萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章