git:fatal the current branch master has no upstream branch

英文解决方案连接,感谢michaeltwofishGoZonerdunni

git本地仓库push远程仓库的时候,报了异常:fatal the current branch master has no upstream branch

但是按提示, git push --set-upstream ../remote-jackygit.git master 并没有解决问题。

经过查询发现目前有两种解决方案:

1.翻译后大致意思是,远程仓库创建时候要建立一个README文件,然后再进行push操作。因为这个文件是远程仓库主分支所必须的,见如下截图。

Create the repo on github; add a README file on github and then clone the github repository.  Creating the README file (or any file actually) is needed in order to get a master branch.Notice how github prompts for creating a README when creating a repository:

2.翻译后大致意思是,如果不想重新创建远程仓库再克隆(针对方案1),或者初始化本地仓库,可以使用下面命令: git push -u origin master,其中origin 表示远程仓库名称,master是远程仓库的push目标分支。-u (推测为update缩写^_^~)表示本地分支将建立对远程仓库目标分支的检测,如果远程仓库目标分支不存在,将新建分支再push;如果存在,将进行push更新。

Instead of creating a new repository on Github, cloning that, or reinitializing your local repository, the following command would have been sufficient:

git push -u origin master

origin stands for the remote name (default is origin), and master is the branch you want to push, in your case it's master, otherwise you would have to change that in the command.
-u means, that your local branch will be setup to track the new created master branch on the origin repository (the master on the origin will be the upstream branch of your local branch). If the branch master doesn't exist on the remote repository, it will be created, otherwise it will be updated (the -u works no matter if it exists or not).

然后,验证此方法,确实可行!

 

 

  • 11
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值