序
在mac上上傳項(xiàng)目到github上,遇到一些問(wèn)題,在此做下記錄;
準(zhǔn)備
- 1 下載安裝git客戶端 http://code.google.com/p/git-osx-installer/downloads/list?can=3
- 2 注冊(cè)github賬號(hào) https://github.com/
創(chuàng)建ssh
由于本地Git倉(cāng)庫(kù)和GitHub倉(cāng)庫(kù)之間的傳輸是通過(guò)SSH加密的郭蕉,所以要在本地生成一個(gè)私鑰和一個(gè)密鑰
- 1
defaults write com.apple.finder AppleShowAllFiles -bool true // 終端 顯示隱藏文件(需要重新運(yùn)行Finder)壶冒。
2 點(diǎn)擊桌面頂部菜單 前往>個(gè)人 看看自己電腦上有沒(méi)有個(gè) .ssh 的隱藏文件寇蚊,有的話個(gè)人建議刪除,新建個(gè)。
3
mkdir .ssh //終端新建個(gè) .ssh文件
- 4
cd .ssh // 進(jìn)入到剛才新建的.ssh文件目錄下
- 5
ssh-Keygen -t rsa -C "your_email@example.com" //后面“ ”里面 隨意輸入個(gè)郵箱就行,回車會(huì)提示你輸入密碼什么的见秤,可以無(wú)視一直回車下去。
- 6
ls -la // 查看是否存在 id_rsa(私鑰) id_rsa.pub(公鑰) 這兩個(gè)東西,如果存在就成功了
- 7
pbcopy < ~/.ssh/id_rsa.pub //拷貝 公鑰
- 8
登陸github针肥,選擇Account Settings-->SSH Keys 添加ssh
Title:xxxxx@gmail.com
Key:打開(kāi)你生成的id_rsa.pub文件,將其中內(nèi)容拷貝至此香伴。
![Uploading 300046-f6da9f16410671bb_190330.png . . .]
06214042-544c2f0cdb50495e95830e7a6d83dbf0.png
⑨ ssh -T git@github.com 新添加到github上的秘鑰左邊的點(diǎn)一開(kāi)始是灰色的慰枕,終端執(zhí)行這個(gè)命令后,刷新網(wǎng)頁(yè)會(huì)看到灰色點(diǎn)變成了綠色即纲。
300046-f6da9f16410671bb.png
創(chuàng)建項(xiàng)目
- 1 打開(kāi)終端具帮,先測(cè)試一下你的帳號(hào)跟github連上沒(méi)有:ssh -T git@github.com 如果出現(xiàn)如下提示,表示你連已經(jīng)連上了.(因?yàn)橛辛说谝徊剑圆挥米约鹤鲞^(guò)多的連接github的操作了蜂厅,另外匪凡,下一次要連接github的時(shí)候記得打開(kāi)第一步的工具).
Hi MiracleHe! You've successfully authenticated, but GitHub does not provide shell access.
- 2 在git創(chuàng)建個(gè)人項(xiàng)目
300046-b24604efdda49dc2.png
300046-8dc7208c8d125a04.png
上傳項(xiàng)目
根據(jù)如下步驟來(lái)
touch README.md //新建一個(gè)記錄提交操作的文檔
git init //初始化本地倉(cāng)庫(kù)
git add README.md //添加
git add * //加入所有項(xiàng)目
git status //檢查狀態(tài) 如果都是綠的 證明成功
git commit -m "first commit"http://提交到要地倉(cāng)庫(kù),并寫一些注釋
git remote add origin git@github.com:youname/Test.git //連接遠(yuǎn)程倉(cāng)庫(kù)并建了一個(gè)名叫:origin的別名
git push -u origin master //將本地倉(cāng)庫(kù)的東西提交到地址是origin的地址掘猿,master分支下
出錯(cuò)問(wèn)題分析
如果輸入$ git remote add origin git@github.com:djqiang(github帳號(hào)名)/gitdemo(項(xiàng)目名).git
提示出錯(cuò)信息:fatal: remote origin already exists.
解決辦法如下:
1病游、先輸入$ git remote rm origin
2、再輸入$ git remote add origin git@github.com:djqiang/gitdemo.git 就不會(huì)報(bào)錯(cuò)了稠通!
3衬衬、如果輸入$ git remote rm origin 還是報(bào)錯(cuò)的話,error: Could not remove config section 'remote.origin'. 我們需要修改gitconfig文件的內(nèi)容
4改橘、找到你的github的安裝路徑滋尉,我的是C:\Users\ASUS\AppData\Local\GitHub\PortableGit_ca477551eeb4aea0e4ae9fcd3358bd96720bb5c8\etc
5、找到一個(gè)名為gitconfig的文件飞主,打開(kāi)它把里面的[remote "origin"]那一行刪掉就好了狮惜!
如果輸入$ ssh -T git@github.com
出現(xiàn)錯(cuò)誤提示:Permission denied (publickey).因?yàn)樾律傻膋ey不能加入ssh就會(huì)導(dǎo)致連接不上github。
解決辦法如下:
1碌识、先輸入$ ssh-agent碾篡,再輸入$ ssh-add ~/.ssh/id_key,這樣就可以了丸冕。
2耽梅、如果還是不行的話,輸入ssh-add ~/.ssh/id_key 命令后出現(xiàn)報(bào)錯(cuò)Could not open a connection to your authentication agent.解決方法是key用Git Gui的ssh工具生成胖烛,這樣生成的時(shí)候key就直接保存在ssh中了眼姐,不需要再ssh-add命令加入了,其它的user佩番,token等配置都用命令行來(lái)做众旗。
3、最好檢查一下在你復(fù)制id_rsa.pub文件的內(nèi)容時(shí)有沒(méi)有產(chǎn)生多余的空格或空行趟畏,有些編輯器會(huì)幫你添加這些的贡歧。
如果輸入$ git push origin master
提示出錯(cuò)信息:error:failed to push som refs to .......
解決辦法如下:
1、先輸入$ git pull origin master //先把遠(yuǎn)程服務(wù)器github上面的文件拉下來(lái)
2赋秀、再輸入$ git push origin master
3利朵、如果出現(xiàn)報(bào)錯(cuò) fatal: Couldn't find remote ref master或者fatal: 'origin' does not appear to be a git repository以及fatal: Could not read from remote repository.
4、則需要重新輸入$ git remote add origingit@github.com:djqiang/gitdemo.git