Ubuntu20.04 用git上传GitHub文件

GitHub

在git commit 第一次时候会让你填邮箱和名字,按照上面的两个代码打就行了

git init

git add .

git commit -m "传输信息"

git push origin main

如果要整个文件夹上传,文件夹里套个要上传的文件,在这个文件夹里操作

中间添加 https,它显示我填过了

git remote add origin https://xxxx

然后因为GitHub的master全部变成了main,直接输main的话会报错这句错

error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/ouluy/Web_server.git'

所以填一句

git branch -m master main

然后再

git push origin main

之后输入密码

如果没有README.md

会报错

! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'git@github.com:raxx/xxar.git'

这时候要先把README.md给下载到你要上传的地方

将自己新写的代码备份到其他地方。

删除本地项目里自己新写的代码。

输入 git pull --rebase origin main

重新上传代码

那我就强制上传覆盖远程文件,
git push -f origin master
原文地址:https://www.cnblogs.com/luoyugongxi/p/14793070.html