使用 github 的人可能不用 git, 但用 git 的人一定會使用 github 。
下邊我舉例說明如何使用 git 與 github旁趟。我的任務(wù)是要把上一個教程《網(wǎng)頁制作實(shí)現(xiàn)評論comment功能》中的代碼上傳到 github 備份艰匙,誰叫我有點(diǎn)健忘限煞。
安裝 Git 版本控制系統(tǒng)
打開下載網(wǎng)頁,安裝程序會以.exe 的形式自動下載到電腦上员凝,然后按照提示一步步進(jìn)行安裝署驻。我在第一次安裝完成后,隨意找了個文件夾點(diǎn)擊右鍵健霹,并沒有發(fā)現(xiàn) Git Init Here旺上, 問題可能出在舊版 "msysgit" 安裝后有 Git Init Here 選項(xiàng),新的 Git 中不再有這個選項(xiàng)糖埋,因此普遍認(rèn)為有三種解決方法:
- 修改注冊表
- 安裝 GitExtensions
- 使用 Git Base Here 打開命令行宣吱,運(yùn)行g(shù)it init
我選擇了最簡單的第三種方法,如何學(xué)友們使用了其它方法解決了這個問題瞳别,請留言給我征候。
Windows 下載地址:https://git-scm.com/download/win
配置 Git
連接本地倉庫與 github 需要設(shè)置 ssh key
$ ssh-keygen -t rsa -C "your_email@youremail.com"
請將 your_email@youremail.com 設(shè)置為你在 github 上注冊的郵箱。
接下來設(shè)置密碼祟敛,直接回車為不設(shè)置密碼疤坝。按照提示,找到 .ssh 文件夾下的 id_rsa.pub 文件馆铁,打開復(fù)制下全部內(nèi)容跑揉。
設(shè)置 github
登陸 github, 選擇setting 選項(xiàng)。
添加 SSH key。
驗(yàn)證是否配置成功
- 在 github 上創(chuàng)建倉庫历谍。
2.使用 Git Bash 打開命令行现拒,輸入
$ ssh -T git@github.com
當(dāng)看到 You’ve successfully authenticated, but GitHub does not provide shell access 時(shí),證明已與 github相連望侈。然后設(shè)置用戶名和郵箱
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"
__注意: user.name 與 "your name"間存在空格具练,由于不認(rèn)真,這簡單的一步困擾了我好久甜无。 __
3.右鍵點(diǎn)擊要上傳的倉庫,選擇 git bash哥遮,添加遠(yuǎn)程地址
$ git remote rm origin
$ git remote add origin git@github.com:yourName/yourRepo.git
yourName 是你在 github 上的用戶名岂丘,yourRepo.git 是剛剛創(chuàng)建的倉庫名。
嘗試上傳一個文件
1.創(chuàng)建 README.txt 文件
2.在命令行輸入以下指令
$ git add README.txt
$ git commit -m "first commit"
$ git push origin master
3.查看 Github
這一階段至此就算是成功了眠饮,我們改天再繼續(xù)聊奥帘。
不積跬步,無以至千里仪召,讓我們一起前進(jìn)寨蹋!
參考資料:
http://1ke.co/course/194
http://stackoverflow.com/questions/42053555/global-git-config-file-does-not-exist
http://stackoverflow.com/questions/38481534/installing-git-on-windows-10-unable-to-access-gitconfig
http://litreily.coding.me/brackets/git/2016/05/15/brackets-git-instructions.html
https://www.youtube.com/watch?v=MJUJ4wbFm_A