第一步:建立git倉庫
cd到你的本地項(xiàng)目根目錄下,執(zhí)行g(shù)it命令,此命令會(huì)在當(dāng)前目錄下創(chuàng)建一個(gè).git文件夾。
git init
第二步:將項(xiàng)目的所有文件添加到倉庫中
git add .
這個(gè)命令會(huì)把當(dāng)前路徑下的所有文件添加到帶上傳的文件文件列表中。
如想添加某個(gè)特定的文件,只需要把 . 換成特定的文件名即可
第三步:將add的文件commit 到倉庫
git commit -m "注釋語句"
第四步:創(chuàng)建自己的Repository
第五步:將本地的倉庫關(guān)聯(lián)到GitHub上
git remote add origin https://自己的倉庫url地址
git remote -v 查看你當(dāng)前項(xiàng)目遠(yuǎn)程連接的是哪個(gè)倉庫地址
如果有錯(cuò)誤信息:fatal: remote origin already exists.
解決方法:
1、先輸入$ ? git remote rm origin?
2、再輸入$ git remote add origin https://自己的倉庫url地址
第六步:上傳代碼到github遠(yuǎn)程倉庫
git push -u origin master
一般上傳之前先拉取一下:
git pull origin master
如果出現(xiàn)以下錯(cuò)誤:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly.
Permission denied (publickey).
fatal: Could not read from remote repository.
解決方法:
進(jìn)入~/.ssh下查看是否存在密鑰對id_rsa和id_rsa.pub,直接運(yùn)行heroku keys:add
如果不存在的話,生成一對
ssh-keygen -t rsa
再然后
heroku keys:add
檢查本地私鑰是否存在于ssh服務(wù)中
eval `ssh-agent -s`
如果出現(xiàn)Could not open a connection to your authentication agent,那么就先運(yùn)行
ssh-agent bash
接著:ssh-add -l
如果沒出錯(cuò),需要添加進(jìn)去
ssh-agent
ssh-add ~/.ssh/id_rsa