標籤:預設 -o tor repo 下載 不能 erp 拷貝 shel
這裡主要講講如何在mac底下使用github,我剛開始使用時,還是費了一點功夫的,因為網上的資料比較雜,有些不是太準確。故將自己的安裝過程比較詳細的分享下,方便有需要的人,攢點人品。
首先你得完成如下兩個工作:
- 下載安裝git用戶端 http://code.google.com/p/git-osx-installer/downloads/list?can=3
- 註冊github帳號 https://github.com/ -->Pricing and Signup -->Create a free account
建立ssh:
接下來開啟終端(不知道終端在哪兒的,就直接在spotlight裡搜terminal):
cd ~/.ssh 檢查是否已經存在
如果存在,(一般情況下都不會存在)先將已有的ssh備份,或者將建立的ssh產生到另外的目錄下
如果不存在,通過預設的參數直接產生ssh:
先 cd -/.ssh 會出現如:
郵箱地址填寫自己註冊github 的郵箱地址.
登陸github,選擇Account Settings-->SSH Keys 添加ssh
Title:[email protected](自己的郵箱)
Key:開啟你產生的id_rsa.pub檔案,(前往檔案夾;路徑是/Users/你的home檔案夾/.ssh/id_rsa.pub,比如:/Users/chendianming/.ssh/id_rsa.pub),之後將其中內容拷貝進去:
開啟終端,先測試一下你的帳號跟github連上沒有:ssh -T [email protected] 如果出現如下提示,表示你連已經連上了.(因為有了第一步,所以不用自己做過多的串連github的操作了,另外,下一次要串連github的時候記得開啟第一步的工具).
如果出現The authenticity of host ‘github.com (192.30.253.112)‘ can‘t be established. Are you sure you want to continue connecting (yes/no)? 請輸入yes
原因: 1.github上沒有與本地倉庫相關聯(少數情況)
2.ssh 不對 (基本上都是這樣的情況)
ssh 解決:
1. cat ~/.ssh/id_rsa.pub 查看ssh是否是自己的(後面是你自己的郵箱說明是自己的),不是說明是ssh問題,是的話就是遠程關聯問題
2. 如果是ssh問題則在git倉庫同目錄 刪除.ssh檔案夾 (隱藏檔案夾)
判斷刪除成功: cat ~/.ssh/id_rsa.pub
出現cat: /c/Users/使用者名稱/.ssh/id_rsa.pub: No such file or directory
3.重新建立ssh ssh-keygen -t rsa -C "[email protected]“
如果出現 Hi domanc! You‘ve successfully authenticated, but GitHub does not provide shell access. 說明成功.
接下來就可以上傳你的代碼了,在github下建自己的Repository。Create a New Repository如下:
Repository name:通常就寫自己自己要建的工程名。
Description:就是你對工程的描述了。
選擇Public。
Add.gitignore 選擇那種語言
Add a license 選擇一種協議,具體見下面這個,也可以自行度娘:
https://www.zhihu.com/question/27114031
上面操作成功後會到:
接下來建立一個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 [email protected]:domanc/test.git
6.git push -u origin master
如果出現一下錯誤:
error: src refspec master does not match any.
引起該錯誤的原因是,目錄中沒有檔案,空目錄是不能提交上去的
error: insufficient permission for adding an object to repository database ./objects
服務端沒有可寫目錄的許可權
錯誤提示:fatal: remote origin already exists.
解決辦法:$ git remote rm origin
錯誤提示:error: failed to push som refs to ........
解決辦法:$ git pull origin master //先pull 下來 再push 上去
剛建立的github版本庫,在push代碼時出錯:
$ git push -u origin master
To [email protected]:******/Demo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to ‘[email protected]:******/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.
網上搜尋了下,是因為遠程repository和我本地的repository衝突導致的,而我在建立版本庫後,在github的版本庫頁面點擊了建立README.md檔案的按鈕建立了說明文檔,但是卻沒有pull到本地。這樣就產生了版本衝突的問題。
有如下幾種解決方案:
1.使用強制push的方法:
$ git push -u origin master -f
這樣會使遠程修改丟失,一般是不可取的,尤其是多人協作開發的時候。
2.push前先將遠程repository修改pull下來
$ git pull origin master
$ git push -u origin master
3.若不想merge遠程和本地修改,可以先建立新的分支:
$ git branch [name]
然後push
$ git push -u origin [name]
出現這個錯誤:
! [rejected] master -> master (non-fast-forward)
詳情見這個 http://blog.csdn.net/chain2012/article/details/7476493
上傳工程到github