The current branch master has no upstream branch(解决)

当我在本地commit完成,直接使用git push 出现了如下错误:

 The current branch master has no upstream branch

提示目前的branch 没有upstream branch.

git pro 里面关于upstream branch的解释:
Checking out a local branch from a remote-tracking branch automatically creates what is called a
“tracking branch” (and the branch it tracks is called an “upstream branch”). Tracking branches are
local branches that have a direct relationship to a remote branch.

意思是远程的branch和本地的branch可以发生联系,这种联系是一种对应关系,当我们push 的时侯本地的就会替换远程的。发生这种关系的branch一个叫做upstream branch(remote),一个叫做tracking branch(local).

git 的push逻辑是:

  • the default push policy was ‘matching’ (push all the branches of the same name, creating them if they don’t exist),
  • the default push policy is now ‘simple’ (push only the current branch, and only if it has a similarly named remote tracking branch on upstream, since git 1.7.11)

也就是说本地的branch必须在远程中有upstream branch 才会push成功。
解决办法是让两个branch发生联系:

 git push --set-upstream origin master

简写

git push -s origin master

这样操作以后系统回复

branch 'master' set up to track 'origin/master'.

这样下一次push可以直接使用

git push

有一个问题是如果我在本地新建一个new_branch那么git push就不能提交了,原因和前面一样。
必须要重新set upstream branch.

git push --set-upstream origin new_branch 

简写

 git push -u origin new_branch
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值