Git master branch has no upstream branch的解决

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

具体原因: 出现这种情况主要是由于远程仓库太多,且分支较多。在默认情况下,git push时一般会上传到origin下的master分支上,然而当repositorybranch过多,而又没有设置关联时,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。同样根据自己的需要,替换originmaster

两个命令的区别是第一条命令是要保证你的远程分支存在,如果不存在,也就无法进行关联。而第二条指令即使远程没有你要关联的分支,它也会自动创建一个出来,以实现关联。

---------------------

本文来自 benben_2015 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/benben_2015/article/details/78803753?utm_source=copy

Git master branch has no upstream branch的解决的更多相关文章

  1. 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:/ ...

  2. 【IDEA】 Can't Update No tracked branch configured for branch master or the branch doesn't exist. To make your branch track a remote branch call, for example, git branch --set-upstream-to origin/master

    IDEA点击GIT更新按钮时,报错如下: Can't UpdateNo tracked branch configured for branch master or the branch doesn' ...

  3. [Practical Git] Switching between current branch and last checkout branch

    When working on a project, it is much easier to work on features and bugs in isolation of the rest o ...

  4. git merge,rebase和*(no branch)

    上一篇:http://blog.csdn.net/xiaoputao0903/article/details/23933589,说了git的分支,相关的使用方法没说到可是仅仅要google就能搜出一大 ...

  5. git常见问题之git pull时Please specify which branch you want to merge with.

    $ git pull时遇到如下提示 $ git pull warning: no common commits remote: Counting objects: 5, done. remote: C ...

  6. Git 协作:Fetch Pull Push Branch Remote Rebase Cherry-pick相关

    前言 学习git的时候,我们首先学习的是最常用的,自己独立开发Software时用的命令: git init //初始化git仓库 git add <file_name> //将文件添加到 ...

  7. eclipse git 一个错误:the current branch is not configured for pull No value for key branch.xxx.merge found

    eclipse git 一个错误:the current branch is not configured for pull No value for key branch.xxx.merge fou ...

  8. git 报错 gitThere is no tracking information for the current branch. Please specify which branch you w

    新建本地分支后将本地分支推送到远程库, 使用git pull 或者 git push 的时候报错gitThere is no tracking information for the current ...

  9. Git master合并分支时提示“Already up-to-date”

    Git master合并分支时提示"Already up-to-date" ​ 在使用Git把当前分支合并到master提示"Already up-to-date&quo ...

随机推荐

  1. C++字符集问题终极分析(可解决乱码问题)

    最近研究vc,windows的东西真是很傻瓜,啥都给你做好,有个好处就是开发方便了. 有个弊端就是完全按微软的一套进行,规则都是它定的,你得知道它的很多api, 开发出来的代码效率不高,不过却可以比较 ...

  2. vector向量容器元素排序与查找

    1.利用标准库函数sort()对vector进行排序 参考源码: #include <algorithm> #include <vector> vector<int> ...

  3. [译] SystemTap

    SystemTap 什么是system Tap ? SystemTap 提供环境用来获得更多关于内核几乎所有组件的信息,用以被进一步分析.SystemTap也可以被当作一种工具,为用户研究和监控内核详 ...

  4. UE4流关卡

    转自:http://blog.ch-wind.com/ue4-level-streaming/ 流关卡可以使得关卡内容只在玩家“需要”的时候才加载,在很多游戏中都有使用这个技术. 当前UE4版本4.1 ...

  5. git 学习 多个提交用同一个commit

    git add .git commit --amend(连续按连个ZZ)git push -f origin ibm_branch(命令行可能不好用,用IDEA force push好用)

  6. Debian7 apt源设置

    刚装完系统时是没有 apt-spy 的,这时候我们可以暂时先找个可用的源代替,如(写在 /etc/apt/sources.list 中): deb http://http.us.debian.org/ ...

  7. FFMPEG: avformat_find_stream_info()函数

    av_find_stream_info()中是要不断的读取数据包,解码获得相应的信息 其中: st->codec->codec_type:0:视频,1:音频,2:数据 st->cod ...

  8. git clone 某一特定分支<转>

    网上搜索自己想要的答案,往往会搜大一大堆感觉没用的,或者看不懂的东西, 最好终于找到了想要答案,特记录一下: ============================================= ...

  9. 信号量sem 的用法

    #include <semaphore.h> sem_t sem; sem_init(&sem, 0, 0); sem_post(&sem); sem_wait(& ...

  10. asp.net的验证码插件及方法、ashx验证码一般处理程序

    需要引入一个ashx的一般处理程序! 把这个程序在前台当作一个图片使用就可以! 前台代码: <td> <img title="看不清?" style=" ...