日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

上传工程到github

發布時間:2023/10/11 综合教程 90 老码农
生活随笔 收集整理的這篇文章主要介紹了 上传工程到github 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這里主要講講如何在mac底下使用github,我剛開始使用時,還是費了一點功夫的,因為網上的資料比較雜,有些不是太準確。故將自己的安裝過程比較詳細的分享下,方便有需要的人,攢點人品。

首先你得完成如下兩個工作:

  1. 下載安裝git客戶端 http://code.google.com/p/git-osx-installer/downloads/list?can=3
  2. 注冊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:xxxxx@gmail.com(自己的郵箱)

Key:打開你生成的id_rsa.pub文件,(前往文件夾;路徑是/Users/你的home文件夾/.ssh/id_rsa.pub,比如:/Users/chendianming/.ssh/id_rsa.pub),之后將其中內容拷貝進去:

打開終端,先測試一下你的帳號跟github連上沒有:ssh -T git@github.com 如果出現如下提示,表示你連已經連上了.(因為有了第一步,所以不用自己做過多的連接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 "your_email@example.com“

如果出現 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 git@github.com: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 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.

網上搜索了下,是因為遠程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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。