mac下將工程提交到Github
第一次提交之前需要創(chuàng)建ssh:
$cd ~/.ssh //檢查是否已經(jīng)存在ssh
如果不存在,通過默認(rèn)的參數(shù)直接生成ssh:
$ssh-keygen -t rsa -c xxxxxx@hotmail.com //注冊Github時的email
之后就是在Github中添加ssh了:
登錄Github,選擇Account Settings —>SSH Keys
添加ssh
Title:xxxxxx@hotmail.com
Key:打開你生成的id_rsa.pub文件,將其中內(nèi)容拷貝至此。
打開終端,先測試一下你的賬號跟Github連上沒有:
$ssh -T git@github.com
如果出現(xiàn)了以下提示,表示已經(jīng)連接成功。
Hi MiracleHe! You've successfully authenticated, but GitHub does not provide shell access.
接下來就可以上傳代碼了,在GIthub上創(chuàng)建自己的Repository:
Repository name:通常就寫自己要建的工程名。
Description:就是對工程的描述。
選擇Public。
點擊”Create repository"
注意,在終端中輸入時,把目錄切換到你要上傳的工程目錄下
touch README.md //新建一個記錄提交操作的文檔
git init //初始化本地倉庫
git add README.md //添加
git commit -m “first commit” //提交到本地倉庫,并寫一些注釋。
git remote add origin git@github.com:your name/Test.git //連接遠(yuǎn)程倉庫并建了一個名叫origin的別名。
git push -u origin master //將本地倉庫的東西提交到地址是origin的地址,master分支下。-u為第一次提交,需要創(chuàng)建master分支,下次就不需要了。
初始化完成之后,我們可以把我們項目的源碼提交上去,使用git add命令:
git add 項目目錄的名字/ //添加需要提交的文件夾,使用git add . 則添加全部
git add project.properties
git add src/
git commit -m “上傳項目源碼” //提交到本地倉庫
git push origin master //將本地倉庫合并到別名為origin地址的master分支下
疑難問題分析和解決:
-
如果輸入
$git remote add origin git@github.com:your name/Test.git提示出錯信息:
fatal:remote origin already exits解決辦法如下:
- 先輸入
$ git remote rm origin- 再輸入
$ git remote add origin git@github.com:your name/Test.git就不會報錯了。
- 如果輸入
$ git remote rm origin還是報錯的話,
error:Could not remove config section ‘remote.origin’我們需要修改config文件的內(nèi)容
- 找到你的Github的安裝路徑
- 找到一個名為gitconfig的文件,打開它把里面的
[remote “origin”]一行刪掉就好了
-
如果輸入
$git push origin master提示出錯信息:
error:failed to push som refs to……..解決辦法如下:
- 先輸入
$ git pull origin master //先把遠(yuǎn)程服務(wù)器Github上的文件拉下來- 再輸入
$ git push origin master- 如果出現(xiàn)報錯
fatal:Couldn’t find remote ref master 或者 fatal:’origin’ does not appear to be a git repository 以及 fatal:Could not read from remote repository- 則需要重新輸入
$ git remote add origin git@github.com:your name/Test.git