一:检查本地项目中是否存在git仓库
git status
没有,好!进入第二步👇(有?直接git add git commit -m 'xxx' git push,聊天end)
二:初始化仓库
git init
三:创建一个远程仓库地址(如有可略)
四:关联远程仓库
git remote add origin 远程仓库
五:推送
git push
一般直接执行git push是会报错的,正如它报错而言你当前是第一次创建仓库,没有远程分支(上游分支),所以需要强制推送
请执行强制推送👇一般创建仓库时大多数都是初始化一个master分支,如果你的分支不是master则需要改下面的分支名称
git push --set-upstream origin master
如果执行了命令报错:src refspec master does not match any
那多半是由于你没有把代码提交到暂存区,而是直接推送了,就好比你3天不吃不喝就想上厕所一样
添加文件
git add .
添加描述
git commit -m 'init'
再次执行git push --set-upstream origin master推送
如果报错:(天哪怎么这么多报错)
To https://gitee.com/iuniko/electron-vite-app.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/iuniko/electron-vite-app.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.
向https://gitee.com/iuniko/electron-vite-app.git
![拒绝]大师->大师(非快进)
错误:未能将某些引用推送到“”https://gitee.com/iuniko/electron-vite-app.git'
提示:更新被拒绝,因为您当前分支的提示已落后
提示:它的远程对应物。整合远程更改(例如。
提示:'git pull…')在再次推动之前。
提示:有关详细信息,请参阅“git push-help”中的“关于快进的注意事项”。
那么就是需要先拉取再推送,也就是执行git pull,执行完后,再次执行git push --set-upstream origin master强制推送
没错,又报错了:
当前分支没有跟踪信息。
请指定要与哪个分支合并。
详见git pull(1)。
git pull<remote><branch>
如果您想为此分支机构设置跟踪信息,可以使用以下方式:
git分支--设置上游为=origin/<branch>master
好吧,看来还需要手动设置关联分支
git branch --set-upstream-to=origin/master master
切换成功,执行下面的命令
git push origin master --force
查看
终于好了。。