提交代碼到github

1. 新建目錄work

命令:mkdir work

2. 初始化git倉庫

進入Vwork,然後命令:git init

3. 配置git

每次 Git 提交時都會引用這兩條信息,說明是誰提交了更新,所以會隨更新內容一起被永久納入歷史記錄:

$ git config --global user.name "John Doe"

$ git config --global user.email [email protected]

4. 創建ssh key

命令:ssh-keygen -t rsa  -C "[email protected]"    , 然後就一直回車,會在主目錄下生成.ssh文件夾,裏面有兩個或三個文件,其中我們只要用到一個,那就是公鑰:id_rsa.pub,這個文件。

5. github添加公鑰

進入github,點擊右邊的setting->SSH keys and GPG keys。

接着點擊New SSH key,將我們第三部的id_rsa.pub的內容複製到key中,title的話隨便取,自己知道就可以了,區別時誰提交的就行。

6. github新建項目repositories

複製項目git地址:[email protected]:vionny/work.git

7. 提交代碼

7.1 提交代碼到本地

新建或拷貝代碼到work目錄,然後pull 和commit 代碼到本地。

7.2 本地文件夾關聯github上的項目

git remote add origin [email protected]:jonny/work.git

將本地文件夾和github倉庫關聯,後面是你自己的github倉庫地址

7.3 拉取github項目的代碼

git pull orgin master

7.4 提交到github

git push origin master

注意:

有可能在7.3和7.4的時候會報錯“

fatal: refusing to merge unrelated histories // 拒絕合併無關歷史

git 的 官方文檔 是這樣描述的:

By default, git merge command refuses to merge histories that do not share a common ancestor. This option can be used to override this safety when merging histories of two projects that started their lives independently. As that is a very rare occasion, no configuration variable to enable this by default exists and will not be added.

默認情況下,git合併命令拒絕合並沒有共同祖先的歷史。當兩個項目的歷史獨立地開始時,這個選項可以被用來覆蓋這個安全。由於這是一個非常少見的情況,因此沒有默認存在的配置變量,也不會添加。

需要這樣才行:git pull origin master --allow-unrelated-histories

至少我的問題是這樣解決了,但是好像還有其他網友也沒法用這個命令解決。

然後在看下github的work目錄下就有代碼了:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章