-
碼雲上創建一個項目,例如 fighting
-
本地創建一個文件夾D:/Java/fighting,然后鼠標右擊選擇git bash here
-
使用 git init 命令,初始化一個git本地倉庫(項目),會在本地創建一個 .git 的文件夾
-
使用git remote add origin fighting的git克隆地址 //添加遠程倉庫 // 示例:git remote add origin https://gitee.com/xxxx/fighting.git// 示例:git remote add origin https://gitee.com/cheng-huanlong/chl.git
-
使用 git pull origin master 命令,將碼雲上的倉庫pull到本地
-
將要上傳的文件,添加到剛剛創建的文件夾fighting里
-
使用git add . 或者 git add + 文件名 (將文件保存到緩存區)
-
使用git commit -m ‘描述新添加的文件內容’ (就是提交代碼的注釋) (文件保存到本地倉庫)
-
使用git push origin master,將本地倉庫推送到遠程倉庫
完成!
git push遇到錯誤: [rejected]master -> master (non-fast-forward)的解決方法
執行git push只之后報如下錯誤:
Username for 'https://gitee.com': **@**.com
fatal: unable to get credential storage lock: File exists
To https://gitee.com/**/**.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/**/**.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解決方法:
git pull origin master --allow-unrelated-histories //把遠程倉庫和本地同步,消除差異
git add .
git commit -m '***'
git push origin master