如題
閑來無事,炒個冷飯。。。
步驟
1. 先本地建倉庫
- 方法一:
執(zhí)行命令(使用git bash或者類似工具,或者IDEA下terminal命令行):
git init
會在當前目錄下創(chuàng)建一個新的空Git庫。
- 方法二:
在IDEA中,執(zhí)行如下操作也可:
此時當前項目下就生成了.git存儲庫。
2. 將文件添加到 .git庫中
執(zhí)行命令,將當前目錄下所有修改添加到git庫里:
git add .
3. 提交修改
提交修改,使用以下命令:
git commit -m "提交信息提示"
4. 在Github/Gitlab/Gitee/Gitea等等創(chuàng)建倉庫
5. 使用以下命令關聯(lián)遠程倉庫
git remote add origin 遠程倉庫地址 # 命名為了origin
或者
git remote add project名 遠程倉庫地址
6. 推送到遠端
git push -u origin(本地倉庫) master(遠端倉庫分支名)
這里注意:對于github和gitlab創(chuàng)建遠程倉庫的默認分支名為 main, 不是master!!!
報錯:
error: src refspec main does not match any
原因就是我們git默認創(chuàng)建的分支是出于master下,但是github以及gitlab上的分支為main分支,官方的解釋是:
GitHub is working on replacing the term “master” on its service with a neutral term like “main” to avoid any unnecessary references to slavery
解決:將本地分支改為main分支
git branch -m master main
然后再次提交。文章來源:http://www.zghlxwxcb.cn/news/detail-617130.html
git push -u project main
最后
放倆傳送門吧:文章來源地址http://www.zghlxwxcb.cn/news/detail-617130.html
- 如何用git創(chuàng)建本地倉庫并且push到遠程倉庫
- 關于git的問題:error: src refspec main does not match any
到了這里,關于Git初始化提交項目代碼并與遠端建立連接的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!