Linux下使用git命令及github項目

來源:互聯網
上載者:User

在linux下搭建git環境
1、建立Github帳號,https://github.com
2、Linux建立SSH密鑰:

ssh-keygen  ##一直預設就可以了

3、將公開金鑰加入到Github賬戶資訊Account Settings->SSH Key
4、測實驗證是否成功。

ssh -T git@github.comHi someone! You've successfully authenticated, but GitHub does not provide shell access.

同步github到本地
1、複製項目到本地:

git clone git://github.com:xxxx/test.git ##以gitreadonly方式複製到本地,只可以讀git clone git@github.com:xxx/test.git  ##以SSH方式複製到本地,可以讀寫git clone https://github.com/xxx/test.git ##以https方式複製到本地,可以讀寫git fetch git@github.com:xxx/xxx.git  ##擷取到本地但不合并git pull git@github.com:xxx/xxx.git ##擷取併合並內容到本地

本地提交項目到github
1、本地配置

git config --global user.name 'onovps'git config --global user.email 'onovps@onovps.com' #全域連絡方式,可選

2、建立Git項目並提交到Github。

mkdir testdir & cd testdirtouch README.mdgit init #初始化一個本地庫git add README.md #添加檔案到本地倉庫git rm README.md #本地倒庫內刪除git commit -m "first commit" #提交到本地庫並備忘,此時變更仍在本地。git commit -a  ##自動更新變化的檔案,a可以理解為autogit remote add xxx git@github.com:xxx/xxx.git  #增加一個遠程伺服器的別名。git remote rm xxx   ##刪除遠程版本庫的別名git push -u remotename master #將本地檔案提交到Github的remoname版本庫中。此時才更新了本地變更到github服務上。

分支版本操作
1、建立和合并分支

git branch #顯示當前分支是mastergit branch new-feature  #建立分支git checkout new-feature  #切換到新分支vi page_cache.inc.phpgit add page_cache.inc.phpgit commit -a -m "added initial version of page cache"git push origin new-feature  ##把分支提交到遠程伺服器,只是把分支結構和內容提交到遠程,並沒有發生和主乾的合并行為。

2、如果new-feature分支成熟了,覺得有必要合并進master

git checkout master  #切換到新主幹git merge new-feature  ##把分支合并到主幹git branch #顯示當前分支是mastergit push  #此時主幹中也合并了new-feature的代碼

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

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.