Git建立本地倉庫並上傳到Gitee的詳細步驟
阿新 • • 發佈:2020-08-21
電腦安裝git客戶端、註冊github賬號並登陸
到本地專案資料夾右鍵選擇git bash here
輸入個人資訊(程式碼提交者)
git config --global user.name "xxxx" git config --global user.email [email protected]
在本地專案目錄建立本地倉庫
git init
輸入命令後項目目錄會有一個隱藏的.git資料夾
上傳所有程式碼到本地倉庫
git add. (注意add後面有個點,與add之間有一空格)
這樣就把程式碼上傳到本地倉庫了
git commit -m "initial commit"
在gitee上新建專案,複製https://gitee.com/xxx/xx.git地址
關聯本地倉庫並上傳程式碼
git remote add origin https://github.com/Yanyf765/hr_sys.git(上步驟複製的地址) git push origin master
報錯:
執行命令:
git pull origin master --allow-unrelated-histories
git 在pull或者合併分支的時候有時會遇到這個介面。可以不管(直接下面3,4步),如果要輸入解釋的話就需要:
1.按鍵盤字母 i 進入insert模式
2.修改最上面那行黃色合併資訊,可以不修改
3.按鍵盤左上角"Esc"
4.輸入":wq",注意是冒號+wq,按回車鍵即可
之後就可以成功的pull,push了
提交到遠端報錯,如下:
src refspec master does not match any
原因:
本地倉庫為空
解決方法:
使用如下命令 新增檔案;
$ git add add.php addok.php conn.php del.php edit.php editok.php ftpsql.sql index.php $ git commit -m "init files"
之後在push過程中出現如下錯誤:
$ git push -u origin master
Warning: Permanently added the RSA host key for IP address 'xx.xx.xxx.xxx' to the list of known hosts.
To [email protected]:hahaha/ftpmanage.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to '[email protected]:hahahah/ftpmanage.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g.,'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
提示使用 git pull 之後在 push
使用如下命令解決:
$ git pull --rebase origin master warning: no common commits remote: Counting objects: 3,done. remote: Total 3 (delta 0),reused 0 (delta 0),pack-reused 0 Unpacking objects: 100% (3/3),done. From github.com:hahah/ftpmanage * branch master -> FETCH_HEAD * [new branch] master -> origin/master First,rewinding head to replay your work on top of it... Applying: init files
繼續push,成功。
總結
到此這篇關於Git建立本地倉庫並上傳到Gitee的文章就介紹到這了,更多相關Git建立本地倉庫內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!