git/github學習筆記

來源:互聯網
上載者:User

1. git 版本控制系統

相比CVS\SVN優勢:

- 支援離線開發,離線Repository
- 強大的分支功能,適合多個獨立開發人員協作
- 速度塊

ps:關於git的更詳細的介紹於優點在此就不介紹了,教大家怎麼用是關鍵。:)

==============運行環境========

系統:windows

git : Git-1.7.3.1-preview20101002.rar  :http://d.download.csdn.net/down/3169511/z_y_liu89

===========================


2. github是一個git項目託管網站

登入位址:https://github.com/signup/free

 

3. 安裝git程式,執行下面操作

$ cd ~/.ssh    //檢查電腦ssh密鑰

如果沒有提示:No such file or directory 說明你不是第一次使用git,執行下面的操作,清理原有ssh密鑰

 $ ls 
config id_rsa id_rsa.pub known_hosts
$ mkdir key_backup
$ cp id_rsa* key_backup
$ rm id_rsa*

獲得密鑰:

ssh-keygen -t rsa -C "defnngj@gmail.com"//填寫email地址,然後一直“斷行符號”ok

開啟本地..\.ssh\id_rsa.pub檔案。此檔案裡面內容為剛才產生人密鑰。

4. 登陸github系統。點擊右上方的 Account Settings--->SSH Public keys ---> add another public keys

把你本地產生的密鑰複製到裡面(key文字框中), 點擊 add key 就ok了

5. 接著開啟git ,測試連接是否成功

$ ssh -T git@github.com

如果提示:Hi defnngj You've successfully authenticated, but GitHub does not provide shell access. 說明你串連成功了

6. 設定使用者資訊:

6.1

$ git config --global user.name "defnngj"//給自己起個使用者名稱
$ git config --global user.email "defnngj@gmail.com"//填寫自己的郵箱

6.2

在github中找到 Account Settings--->Account Admin ,找到一下資訊:

Your API token is e97279836f0d415a3954c1193dba522f ---keep it secret! Changing your password will

generate a new token

$ git config --global github.user defnngj      //github 上的使用者名稱
$ git config --global github.token e97279836f0d415a3954c1193dba522f

 

====================建立一個項目========================

 1. 回到github首頁,點擊頁面右下角“New Repository”

填寫項目資訊:

project name: hello world

description : my first project

點擊“Create Repository” ; 現在完成了一個項目在github上的建立。

2. 我們需要使用git在本地建立一個相同的項目。

$ makdir ~/hello-world    //建立一個項目hello-world
$ cd ~/hello-world //開啟這個項目
$ git init //初始化
$ touch README
$ git add README //更新README檔案
$ git commit -m 'first commit'//提交更新,並注釋資訊“first commit”
$ git remote add origin git@github.com:defnngj/hello-world.git //串連遠程github項目
$ git push -u origin master //將本地項目更新到github項目上去

 現在查看github上面的hello world 項目,是不是發現已經將本地中的README檔案更新上來了。 恭喜!

 

------------------------------------關於可能出現的錯誤----------------------------------

1.在執行

$ git remote addorigin git@github.com:defnngj/hello-world.git

錯誤提示:fatal: remote origin already exists.

解決辦法:

$ git remote rm origin

然後在執行:$ git remote add origin git@github.com:defnngj/hello-world.git 就不會報錯誤了

 

2. 在執行

$ git push origin master

錯誤提示:error:failed to push som refs to.......

解決辦法:

$ git pull origin master //先把遠程伺服器github上面的檔案拉先來,再push 上去。

 

---------------------------後記-----------------------------------------------------------------------

本文是參考官方協助進行的:http://help.github.com/win-set-up-git/ 基本與官方步驟相同,我在此屬於翻譯了一下!

關於更過的學習:請登陸: http://progit.org/book/zh/進行學習。

本來關於此類知識應該屬於開發的,本人從事測試工作,因為老大現在在推行git的使用,所以,就花了時間,初步的學習了一下,為了更好的測試嘛。呵呵。

第二個原因,看到有個樂師用版本管理系統(SVN)來更新和管理自己的樂譜,這個很有意思。版本管理系統並不局限於代碼的管理。而且版本管理系統的思想也很有意思。

關於理論上的東西,請參考其它文檔。

 
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.