1.打開終端,輸入
cd ~/.ssh
這個是檢查你的ssh
的是否存在的,如果存在,先將已有的ssh
備份,或者將新建的ssh
生成到另外的目錄下(如果第一次配置一般都是不存在的),不存在,你將會看到如下:
接下來你就需要用默認的參數生成ssh,終端輸入
ssh-keygen -t rsa -C xxxxx@gmail.com
這里的xxxxx@gmail.com
就是你注冊github
時的郵箱地址,比如我的是chw_loveway@163.com
,那么我的終端就應該輸入
ssh-keygen -t rsa -C fengnoku@126.com
然后一直回車,直到這樣
如果要修改ssh
生成目錄,在粗體位置處輸入要生成的路徑,選擇默認的話,會生成在 ~/.ssh
下
2.打開你的github,按着下面的步驟
點擊左側的New SSH key 然后添加
上面的 Title
:填寫你注冊的郵箱號,這里就是fengnoku@126.com key
:填寫你的生成的id_rsa.pub
文件將里面的內容copy
到此
/Users/fengnovo/.ssh/id_rsa.pub 復制到前往即可
選擇文本編輯打開即可。
3.測試一下你的賬號跟github
連上了沒有,打開終端,輸入
ssh -T git@github.com
如果出現
Hi Loveway! You've successfully authenticated, but GitHub does not provide shell access.
就表示你已經連上了,如圖
4.
在github新建git
touch README.md //新建一個記錄提交操作的文檔 git init //初始化本地倉庫 git add README.md //添加 git add * //加入所有項目 git status //檢查狀態 如果都是綠的 證明成功 git commit -m "first commit"//提交到要地倉庫,並寫一些注釋 git remote add origin git@github.com:youname/Test.git //連接遠程倉庫並建了一個名叫:origin的別名 git push -u origin master //將本地倉庫的東西提交到地址是origin的地址,master分支下
出錯:
1.git commit -m 'test' 出現下面錯誤
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "lint" npm ERR! node v7.2.1 npm ERR! npm v3.10.10 npm ERR! missing script: lint npm ERR! npm ERR! If you need help, you may report this error at: npm ERR! <https://github.com/npm/npm/issues>
把.git/hooks
目錄下的所有文件都刪掉。參考https://github.com/ruanyf/jstraining/issues/24
參考鏈接
http://www.jianshu.com/p/3cc188964dbf
https://apple.stackexchange.com/questions/93002/how-to-properly-update-git-on-mac
http://www.jianshu.com/p/e7501b968256
http://www.07net01.com/2015/08/895617.html
https://github.com/ruanyf/jstraining/issues/24