在push代码时,出现“git master branch has no upstream branch”问题的原因是没有将本地的分支与远程仓库的分支进行关联。如下图所示:

具体原因: 出现这种情况主要是由于远程仓库太多,且分支较多。在默认情况下,git push时一般会上传到origin下的master分支上,然而当repository和branch过多,而又没有设置关联时,git就会产生疑问,因为它无法判断你的push目标。

Git 的 “master” 分支并不是一个特殊分支。 它就跟其它分支完全没有区别。 之所以几乎每一个仓库都有 master 分支,是因为git init命令默认创建它,并且大多数人都懒得去改动它。
远程仓库名字 “origin” 与分支名字 “master” 一样,在 Git 中并没有任何特别的含义一样。origin” 是当你运行git clone时默认的远程仓库名字。 如果你运行 git clone -o booyah,那么你默认的远程分支名字将会是 booyah/master

解决办法其实就是确定这两个值,方法有两种:

  • 第一种如上图中的提示:git push --set-upstream origin master。其中的origin是你在clone远程代码时,git为你创建的指向这个远程代码库的标签,它指向repository。为了能清楚了解你要指向的repository,可以用命令git remote -v进行查看。master是你远程的branch,可以用git branch -a查看所有分支,远程分支是红色的部分。然后确定好这两个值后,将值换掉即可。
  • 另一种方法是:git push -u origin master。同样根据自己的需要,替换origin和master。
    两个命令的区别是第一条命令是要保证你的远程分支存在,如果不存在,也就无法进行关联。而第二条指令即使远程没有你要关联的分支,它也会自动创建一个出来,以实现关联。

————————————————
版权声明:本文为CSDN博主「benben_2015」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/benben_2015/article/details/78803753

Git使用中报错fatal: The current branch master has no upstream branch.解决方案相关推荐

  1. 如果在git配置中报错fatal: Authentication failed for ‘‘,其实就是凭证失败的意思

    1.首先你需要确认你的账号密码是否正确,或者近期修改过密码,我就是修改了密码,密码错误导致 2.查看凭证并修改凭证,步骤如下: a.打开控制面板中的---用户账号--凭据管理---windows凭据- ...

  2. Git报错:fatal: The current branch main has no upstream branch

    Git报错:fatal: The current branch main has no upstream branch 参考:https://blog.csdn.net/benben_2015/art ...

  3. 报错 fatal: The current branch html has no upstream branch. To push the current branch and set the

    场景: 远程上有已存在的项目的后端代码,想要把这个项目的前端代码推送上去. 做的步骤: 1.git status 2. git add . 注意add和.之间有空格 3.git commit - m ...

  4. 【git报错】The current branch dev has no upstream branch. To push the current branch and set the remote

    发现问题 本地新建了一个dev分支,然后把dev分支下的代码push到远程仓库中,使用git push,但是报错了,如下: fatal: The current branch dev has no u ...

  5. git 本地新建分支上传报错The current branch dev has no upstream branch.To push the current branch and setremote

    项目本地初始化后,commit执行完毕,然后执行git push,报如下错误: $ git push fatal: The current branch dev has no upstream bra ...

  6. fatal: The current branch dev_zgd has no upstream branch.

    E:\09-code\06-Turbulent_flow_spectrum>git push fatal: The current branch dev_zgd has no upstream ...

  7. fatal: The current branch dev has no upstream branch. To push the current branch and set the remote

    fatal: The current branch dev has no upstream branch. To push the current branch and set the remote ...

  8. git配置报错fatal: Authentication failed for ‘‘问题解决

    git配置报错fatal: Authentication failed for ''问题解决 参考文章: (1)git配置报错fatal: Authentication failed for ''问题 ...

  9. git使用报错:fatal: Couldn't find remote ref master的解决方法

    git使用报错:fatal: Couldn't find remote ref master的解决方法 fatal: Couldn't find remote ref master 翻译过来就是:致命 ...

最新文章

  1. 使用create-react-app遇到问题解决方案汇总
  2. Jenkins中连接Git仓库时提示:无法连接仓库:Error performing git command: git ls-remote -h
  3. 有滋有味了freeeim
  4. Log4j中的AsyncAppender的实现原理
  5. [物理学与PDEs]第1章习题14 求解 rot 方程
  6. vue 内存溢出问题解决
  7. 以下文件中的行尾不一致,要将行尾标准化吗?+乱码
  8. web框架--MVC、MTV
  9. 如何用Java的Robot完成模拟鼠标移动和键盘输入(可应用刷网课)
  10. 【合集】高等数学随堂笔记-乐经良老师-全系列内容汇总
  11. 算法工程师面试基础题目及答案
  12. mysql中update语句怎么设置变量_MySQL数据库update语句使用详解
  13. 2017-11-28 clac 简易计算器
  14. 美团Android开发工程师岗位职能要求,薪资翻倍
  15. Aras Innovator: 如何在Form中放入图片
  16. CPU,操作系统,应用软件,安装时的32位与64位区别收集总结
  17. C++核心准则​讨论:析构,释放和交换操作必须永不失败
  18. 知乎:人工智能最终会代替数学家或理论物理学家吗?
  19. 58同城CTO邢宏宇:云服务助力企业多元化飞速发展
  20. Mac 卸载 隐蔽软件 Core_Sync 的步骤

热门文章

  1. NetBeans 时事通讯(刊号 # 74 - Sep 30, 2009)
  2. C语言之利用,函数的命名及变量的作用域实现两个数之间的交换。
  3. spring cloud之Feign的使用
  4. 【Python】从键盘输入一个大于1的整数N,判断是否为素数
  5. 【Markdown】新手快速入门基础教程
  6. 【C语言】判断某一正整数是否为完数
  7. C#LeetCode刷题之#66-加一(Plus One)
  8. url散列算法原理_如何列出与网站相关的所有URL
  9. web开发的一些工具技巧_有用的技巧可帮助您建立Web开发人员的良好习惯
  10. 技术交流论坛_天气预报|“第一届国家建筑工程与材料测试技术论坛”暨“第七届全国建筑材料测试技术”交流会...