【Github】hint: Updates were rejected because the remote contains work that you do

Q:git push报错

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.

翻译

提示:更新被拒绝,因为远程包含您所做的工作
提示:不要在本地使用。这通常是由另一个存储库推送引起的
提示:对于相同的ref。您可能需要首先集成远程更改
提示:(例如,“git pull…”)然后再次按下
提示:有关详细信息,请参阅“git推送-帮助”中的“关于快进的说明”

A:这是因为在上传的时候,远程仓库中有着本地仓库没有的文件(与远程仓库的内容不一致),即导致本地仓库和远程有不同的开始点,也就是两个仓库没有共同的 commit ,所以无法提交,解决方法如下:

1. git pull origin main --allow-unrelated-histories

2.git pull origin main

3.git init		

4.git remote add origin ssh://[email protected]:Hahalim2022y/slam_test.git

5.git add .		

6.git commit -m 'test'

7.git push -u origin main

参考教程https://www.cnblogs.com/yanhuidj/p/9301328.html

正确的提交过程如下:

git init                           //初始化仓库
git add .(文件name)                //添加文件到本地 
git commit -m “first commit”      //添加文件描述信息
git remote add origin  远程仓库地址 //链接远程仓库 
git pull origin master           // 把本地仓库的变化连接到远程仓库master/main分支
git push -u origin master        //把本地仓库的文件推送到远程仓库master/main分支

你可能感兴趣的:(GitHub,github,git)