本機(jī)操作
1.打開終端輸入指令
????git --version
檢查本地是否安裝了git

如果沒有,在終端輸入sudo apt-get install git安裝git
2.生成密鑰對,此步驟如果遇見輸入密碼時,連續(xù)按回車即可。
????ssh-keygen -C "****@***.com" -f ~/.ssh/github? ?#此處的郵箱是你的郵箱地址

3.查看公鑰
? ? cat ~/.ssh/github.pub

4.登陸Github
點(diǎn)擊右上角個人頭像 --> 選擇Settings --> 選擇左側(cè)對話框中的SSH and GPG keys?--> 點(diǎn)擊右上角New SSH key
此時會出現(xiàn)如下界面:

將第3步中列出的公鑰拷貝到上圖的Key區(qū)域,Title任意。
5.檢查本地是否能遠(yuǎn)程訪問github服務(wù)器,出現(xiàn)You’ve successfully authenticated,說明認(rèn)證通過。
輸入指令
????ssh -T git@github.com

配置git
即利用自己的用戶名和email地址配置git
????git config --global user.name "你的github用戶名"
????git config --global user.email "你的github郵箱地址"
推送本地內(nèi)容到Github上已有倉庫
從github上將該倉庫clone下來
????git clone https://github.com/你的github用戶名/github倉庫名.git? ?# 這里可以直接將倉庫的HTTP復(fù)制過來
對clone下來的倉庫進(jìn)行更改,例如,添加一個新的文件
????touch Readme_new
對剛剛的更改進(jìn)行提交,該步不可省略!(其實(shí)是提交到git緩存空間)
????git add Readme_new
????git commit -m 'add new readme file'
push
首先,需要將本地倉庫與github倉庫關(guān)聯(lián)(關(guān)聯(lián)僅僅需要做一次就可以?。。?/b>
????git remote add origin https://github.com/你的github用戶名/你的github倉庫.git? ?# 這里可以直接將倉庫的HTTP復(fù)制過來
有時,會出現(xiàn)fatal: remote origin already exists.,那么,需要輸入git remote rm origin 解決該問題
然后,push,此時,可能需要輸入github賬號和密碼,按要求輸入即可
????git push origin master
注:有時,在執(zhí)行g(shù)it push origin master時,報(bào)錯:error:failed to push som refs to…….,那么,可以執(zhí)行
????git pull origin master
至此,github上已有的倉庫的便有了更新。
如果需要添加文件夾,有一點(diǎn)需要注意:該文件夾不能為空!否則不能成功添加