git push 操作

git push 的格式详见 这里


之前 git push 的默认操作是matching:

all your branches were sent to the remote as long as there already are branches of the same name over there.


在新出的 Git-1.8.0 中提到在下个版本中(注意不是1.8.0)会将 git push 的默认操作设为simple:

We will use the "simple" semantics that pushes the current branch to the branch with the same name, only when the current branch is set to integrate with that remote branch.


强烈建议用 git push 时输入完整的命令,而不是简单的 git push,因为你不知道默认的 git push 到底会做什么意想不到的操作。

$ git push <repository> <refspec> …

如: 提交本地 test 分支作为远程的 master 分支

$ git push origin test:master 

提交本地 test 分支作为远程的 test 分支

$ git push origin test:test

如果要删除远程的某个分支(test),把本地分支参数设为空,可以理解为把null推送到远程某个分支,远程分支不就没了。

$ git push origin :test

附:

强推,即利用强制覆盖的方式用本地的分支替代远程库中的分支,慎用:

$ git push -f origin test:test

设置 git push 的默认操作:

$ git config --global push.default upstream

(push 的操作方式有四种:nothing,matching,upstream,current。在Git 1.8.0中说到的会增加的simple方式,见 release-note)


还有,有时候 git push 的时候出现这种错误:

$ git push
fatal: The current branch hotfix has no upstream branch.
这是没有指定当前分支跟踪的远程分支,所以git不知道要推送到哪,可以用git push --set-upstream设定:

$ git push --set-upstream origin hotfix
...
Branch hotfix set up to track remote branch hotfix from origin.



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值