上传工程到github
這里主要講講如何在mac底下使用github,我剛開始使用時(shí),還是費(fèi)了一點(diǎn)功夫的,因?yàn)榫W(wǎng)上的資料比較雜,有些不是太準(zhǔn)確。故將自己的安裝過程比較詳細(xì)的分享下,方便有需要的人,攢點(diǎn)人品。
首先你得完成如下兩個(gè)工作:
- 下載安裝git客戶端 http://code.google.com/p/git-osx-installer/downloads/list?can=3
- 注冊(cè)github賬號(hào) https://github.com/ -->Pricing and Signup -->Create a free account
創(chuàng)建ssh:
接下來打開終端(不知道終端在哪兒的,就直接在spotlight里搜terminal):
cd ~/.ssh 檢查是否已經(jīng)存在
如果存在,(一般情況下都不會(huì)存在)先將已有的ssh備份,或者將新建的ssh生成到另外的目錄下
如果不存在,通過默認(rèn)的參數(shù)直接生成ssh:
先 cd -/.ssh 會(huì)出現(xiàn)如下圖:
郵箱地址填寫自己注冊(cè)github 的郵箱地址.
登陸github,選擇Account Settings-->SSH Keys 添加ssh
Title:xxxxx@gmail.com(自己的郵箱)
Key:打開你生成的id_rsa.pub文件,(前往文件夾;路徑是/Users/你的home文件夾/.ssh/id_rsa.pub,比如:/Users/chendianming/.ssh/id_rsa.pub),之后將其中內(nèi)容拷貝進(jìn)去:
打開終端,先測(cè)試一下你的帳號(hào)跟github連上沒有:ssh -T git@github.com 如果出現(xiàn)如下提示,表示你連已經(jīng)連上了.(因?yàn)橛辛说谝徊?,所以不用自己做過多的連接github的操作了,另外,下一次要連接github的時(shí)候記得打開第一步的工具).
如果出現(xiàn)The authenticity of host 'github.com (192.30.253.112)' can't be established. Are you sure you want to continue connecting (yes/no)? 請(qǐng)輸入yes
原因: 1.github上沒有與本地倉庫相關(guān)聯(lián)(少數(shù)情況)
2.ssh 不對(duì) (基本上都是這樣的情況)
ssh 解決:
1. cat ~/.ssh/id_rsa.pub 查看ssh是否是自己的(后面是你自己的郵箱說明是自己的),不是說明是ssh問題,是的話就是遠(yuǎn)程關(guān)聯(lián)問題
2. 如果是ssh問題則在git倉庫同目錄 刪除.ssh文件夾 (隱藏文件夾)
判斷刪除成功: cat ~/.ssh/id_rsa.pub
出現(xiàn)cat: /c/Users/用戶名/.ssh/id_rsa.pub: No such file or directory
3.重新創(chuàng)建ssh ssh-keygen -t rsa -C "your_email@example.com“
如果出現(xiàn) Hi domanc! You've successfully authenticated, but GitHub does not provide shell access. 說明成功.
接下來就可以上傳你的代碼了,在github下建自己的Repository。Create a New Repository如下:
Repository name:通常就寫自己自己要建的工程名。
Description:就是你對(duì)工程的描述了。
選擇Public。
Add.gitignore 選擇那種語言
Add a license 選擇一種協(xié)議,具體見下面這個(gè),也可以自行度娘:
https://www.zhihu.com/question/27114031
上面操作成功后會(huì)到:
接下來創(chuàng)建一個(gè)test工程,然后在終端輸入一下命令:
1.cd /Users/chendianming/Desktop/test
2.git init
3.git add -A
4.git commit -m "init file"
5.git remote add origin git@github.com:domanc/test.git
6.git push -u origin master
如果出現(xiàn)一下錯(cuò)誤:
引起該錯(cuò)誤的原因是,目錄中沒有文件,空目錄是不能提交上去的
error: insufficient permission for adding an object to repository database ./objects
服務(wù)端沒有可寫目錄的權(quán)限
錯(cuò)誤提示:fatal: remote origin already exists.
解決辦法:$ git remote rm origin
錯(cuò)誤提示:error: failed to push som refs to ........
解決辦法:$ git pull origin master //先pull 下來 再push 上去
剛創(chuàng)建的github版本庫,在push代碼時(shí)出錯(cuò):
$ git push -u origin master
To git@github.com:******/Demo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
網(wǎng)上搜索了下,是因?yàn)檫h(yuǎn)程repository和我本地的repository沖突導(dǎo)致的,而我在創(chuàng)建版本庫后,在github的版本庫頁面點(diǎn)擊了創(chuàng)建README.md文件的按鈕創(chuàng)建了說明文檔,但是卻沒有pull到本地。這樣就產(chǎn)生了版本沖突的問題。
有如下幾種解決方法:
1.使用強(qiáng)制push的方法:
$ git push -u origin master -f
這樣會(huì)使遠(yuǎn)程修改丟失,一般是不可取的,尤其是多人協(xié)作開發(fā)的時(shí)候。
2.push前先將遠(yuǎn)程repository修改pull下來
$ git pull origin master
$ git push -u origin master
3.若不想merge遠(yuǎn)程和本地修改,可以先創(chuàng)建新的分支:
$ git branch [name]
然后push
$ git push -u origin [name]
出現(xiàn)這個(gè)錯(cuò)誤:
! [rejected] master -> master (non-fast-forward)
詳情見這個(gè) http://blog.csdn.net/chain2012/article/details/7476493
總結(jié)
以上是生活随笔為你收集整理的上传工程到github的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu_5139 概率问题
- 下一篇: angular1.x + ES6开发风格