git推送代码报错:fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream

情景再现

远程新建仓库,然后本地 git bash执行以下代码

git init
git add .
git commit -m 'xxx'
git remote add origin https://username@xxx.com/xxx.git
git push

在执行git push的时候出现“ The current branch master has no upstream branch.”问题的原因是没有将本地的分支与远程仓库的分支进行关联,如图

 对应的中文意思:

fatal: 当前分值 master 没有对应的上游分支。为推送当前分支并建立与远程上游的跟踪,使用 git push --set-upstream origin master

  简单来说就是本地仓库跟远程仓库关联不起来,对应不上,不知道推到哪里去。

 

原因:在默认情况下,git push时一般会上传到origin下的master分支上,当repositorybranch过多,又没有设置关联时,git就会产生疑问,因为它无法判断你的push目标。

 

解决办法:

  1、执行上图中 git push --set-upstream origin master 命令即可,会自动进行关联和推送操作

  2、执行 git push -u origin master,  这个命令也是当你新建完远程仓库后github的提示操作,只是它把master分支改名为main分支,如下图所示;这里的origin master即对应你执行了 git remote add origin https://username@xxx.com/xxx.git 对应仓库的master分支;

        

posted @   Amerys  阅读(15411)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示