##一、安裝msysGit
- 下載安裝包,網址Git下載,這裏我使用的是Git-2.12.1版本
- 安裝過程:雙擊
.exe
文件,單擊next
,出現組件選擇界面,由於所有默認組件都已勾選,可以直接進入next
,選擇Use Git Bash only
, 點擊next
,直到程序安裝。
##二、初始設置
1. 設置姓名和郵箱地址:
打開git bash 命令框,輸入如下命令:
$ git config --global user.name "Firstname Lastname "
$ git config --global user.email "[email protected]"
這個命令會在~/.gitconfig
中輸出設置文件,如需更改可直接編輯這個設置文件。由於GitHub上公開倉庫時這裏的姓名和郵箱也會被公開,所以儘量不要使用不便公開的信息。
###2. 提高命令輸出的可讀性
將 color.ui
設置爲auto
:
$ git config --global color.ui auto
##三、使用前的準備
###1.創建賬戶
打開github註冊頁面,進行註冊
###2.設置SSH Key
輸入:
$ ssh-keygen -t rsa -C "[email protected]"
輸出:
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/wth/.ssh/id_rsa): (回車)
Created directory '/c/Users/wth/.ssh'.
Enter passphrase (empty for no passphrase):(輸入密碼)
Enter same passphrase again:(再次輸入密碼)
再次輸出:
Your identification has been saved in /c/Users/wth/.ssh/id_rsa.(私有祕鑰)
Your public key has been saved in /c/Users/wth/.ssh/id_rsa.pub.(公開密鑰)
The key fingerprint is: ****
The key's randomart image is: ***
###3.添加公開密鑰
在github中添加公開密鑰就可以用私有祕鑰進行認證了
點擊github網站右上角Settings
,進入SSH and GPG Keys
菜單,設置 Title
和 Key
,key
部分的內容粘貼id_rsa.pub文件裏的內容。
查看id_rsa.pub內容的命令:
$ cat ~/.ssh/id_rsa.pub
完成以上設置,就可以用私人祕鑰與github進行認證和通信了
檢驗:
$ ssh -T [email protected]
輸入第2步中設置的密碼就會顯示:
Hi bigdatanjupt2017! You've successfully authenticated, but GitHub does not provide shell access.
##四、使用
###1.創建倉庫
點擊New repository
**這裏需要注意的是
Initialize this repository with a README
,如果勾選了,github會自動楚書畫倉庫病設置README文件,讓用戶可以立刻克隆這個倉庫,如果是想添加已有的git倉庫,建議不勾選,手動push
點擊 Create repository
即創建成功,生成對應倉庫的網頁。
##五、公開代碼
###1.clone 已有倉庫
$ git clone [email protected]:bigdatanjupt2017/helloworld.git
$ cd helloworld
###2.編寫代碼
在上面創建的文件夾中編寫自己需要編寫的代碼文件:
查看git狀態命令
$ git status
###3.提交
$ git add hello_world.py (暫存)
$ git commit -m "Add hello word script by python" (提交)
$ git log (查看提交日誌)
###4.push
$ git push
至此我們就可以在github上查看自己編寫的代碼了。