Github教程(0)

Grey Zeng發表於2015-12-14

Git下載:https://git-for-windows.github.io/

我下載的版本是:Git-2.6.3-64-bit.exe

安裝:略 預設選項點選"下一步"即可

 

安裝完畢後

 

1.開啟Git Bash

 

設定使用Git時候的名字和郵箱地址

$ git config --global user.name "yourname"

$ git config --global user.email "youremail@email.com"

 

 

 

2.註冊Github賬戶:https://github.com/

 

3.設定SSH Key,在Git Bash中輸入:

ssh-keygen –t rsa –C "github register email"

 

注: github register email這裡寫你在第二步註冊Github賬戶的郵箱地址

然後按下回車,並設定認證密碼(也可不設定)

回車,會得到兩個檔案:id_rsa(私有金鑰),id_rsa.pub是公開金鑰。

這兩個檔案預設在C:\Users\Username\.ssh目錄下

 

4.新增公開金鑰:

進入你的Github賬戶,在右上角選擇SettingàSSH keysàAdd SSH key, 其中,Title輸入一個名稱,在Key處貼上id_rsa.pub中的內容。

 

5.此時就可以用私人金鑰和Github進行認證和通訊,在Git Bash中輸入:

ssh –T git@github.com

 

提示:Are you sure you want to continue connecting (yes/no)?

輸入:yes 回車

顯示:Hi yourname! You've successfully authenticated, but Github does not provide shell access.

 

 

接下來,演示一個Github的HelloWorld示例:

  1. 進入Github賬戶,點選New repository
  2. Repository name輸入Hello
  3. Description項輸入一些對倉庫的描述資訊(選填)
  4. Public/Private選項勾選Public
  5. Initialize this repository with a README 選項選上
  6. 點選Create Repository即可建立一個Repository
  7. 點選進入Hello這個Repository,拷貝這個Repository的Web Address

  8. 將Hello這個Repository clone至本地,開啟Git Bash,輸入:

     

    git clone your repository's Web Address 

    提示:repository's Web Address就是上一步驟拷貝的URL

  9. Git Bash輸入cd Hello,在Hello目錄下增加一個檔案,比如T.java
  10. 將T.java新增到暫存區,Git Bash中輸入:

     

    git add T.java 
  11. 提交T.java, Git Bash中輸入:

     

    git commit –m "this is your comment" 

     

  12. Push到Github上的倉庫
    git push 

     

    進入Github賬戶中的Hello Repository,即可檢視push進去T.java這個檔案

  13. 檢視提交日誌:

     

    git log 

     

     

     

     

相關文章