- 打開(kāi)終端易核,進(jìn)入項(xiàng)目文件夾
- 輸入git init
- 配置 ssh , 輸入:ssh-keygen -t rsa -C "登錄github的郵箱"
- 需要注意的是州刽,這里是設(shè)置生成ssh key的路徑,直接回車(chē)則在默認(rèn)路徑下生成浑此;也可以輸入自己需要的路徑,或者為不同的項(xiàng)目設(shè)置不同的ssh key路徑;我們默認(rèn)回車(chē), 提示要輸入密碼允跑,跳過(guò),2次回車(chē),不設(shè)置密碼
- 執(zhí)行命令:pbcopy < ~/.ssh/id_rsa.pub 聋丝,將你的 ssh 代碼復(fù)制到剪貼板
- 回到github上索烹,點(diǎn)擊頭像進(jìn)入設(shè)置,再進(jìn)入SSH and GPG keys弱睦,點(diǎn)擊 New SSH key百姓,Title隨便填(一般是項(xiàng)目名稱(chēng)); 在Key里面粘貼剛剛復(fù)制的ssh代碼况木, 保存
- 輸入命令:ssh -T @git@github.com
- 當(dāng)successfully之后垒拢,在 git config 里設(shè)置一下你的 github 登錄名以及登陸郵箱,執(zhí)行以下兩個(gè)命令:
- 執(zhí)行命令:git add . (這個(gè)點(diǎn)表示更改所有的改動(dòng))
- 執(zhí)行命令:git commit -m "first commit"
- 執(zhí)行命令:git remote add origin https://github.com/你的用戶(hù)名/github項(xiàng)目名.git(地址可以到github的項(xiàng)目下復(fù)制過(guò)來(lái))
- 執(zhí)行命令:git push -u origin master(成功)
我遇到的報(bào)錯(cuò)及解決辦法
- 連接github時(shí)火惊,公鑰出現(xiàn)問(wèn)題求类。執(zhí)行 ssh -vT git@github.com后出現(xiàn)如下顯示:
Permission denied (publickey)
1. 首先,清除所有的key-pair
2. ssh-add -D
3. rm -r ~/.ssh
4. 刪除你在github中的public-key
5. 重新生成ssh密鑰對(duì)
6. ssh-keygen -t rsa -C "xxx@xxx.com"
7. chmod 0700 ~/.ssh
8. chmod 0600 ~/.ssh/id_rsa*
9. pbcopy < ~/.ssh/id_rsa.pub
10. 回到github上屹耐,點(diǎn)擊頭像進(jìn)入設(shè)置尸疆,再進(jìn)入SSH and GPG keys,點(diǎn)擊 New SSH key惶岭,Title隨便填(一般是項(xiàng)目名稱(chēng))仓技; 在Key里面粘貼剛剛復(fù)制的ssh代碼, 保存
11. ssh -T git@github.com
fatal: remote origin already exists.
1. git remote rm origin
2. git remote add origin https://github.com/你的用戶(hù)名/github項(xiàng)目 就可以了
3. 如果還報(bào)錯(cuò)俗他,找到git的安裝路徑下的名為gitconfig的文件, 把里面的[remote "origin"]那一行刪掉
The requested URL returned error: 403 Forbidden while accessing
1. 進(jìn)入項(xiàng)目根目錄脖捻,編輯.git目錄下的config文件即可
2. 原來(lái)的url = https://github.com/laibinweb/react-start.git
3. 修改成url = https://laibinweb@github.com/laibinweb/react-start.git
4. 回到終端, 重新git push