git push 远程新分支

git clone #从远程克隆

进行一些编辑后

git add .

git commit -m "xxx"

git push #将master推送到master

git checkout -b test #新建test分支

编辑

git add .

git commit -m "xxxx"

git push origin test:haha #将本地test分支推送到远程haha分支

git branch -a

显示如下

  master
* test
  remotes/origin/haha
  remotes/origin/master


git push 时候提醒

获取远程代码修改后,想要push到远端与原来不同的新分支,可以使用下面的命令实现:
git push origin 本地分支:远端希望创建的分支

例如git下来的分支为master

git branch
>>> *master
git push origin master:my_remote_new_branch
#远端即可创建新的分支my_remote_new_branch,提交本地修改


git push origin :haha #删除远程分支

git push origin test #表示git push origin test:test 远端分支与本地分支同名

如果想要单单使用 git push就推送 需要设置upstream

git branch --set-upstream-to=origin/test

此时,修改过后,add commit
然后直接git push 不加任何参数,就推送到了远端。

如果是
git push origin test:haha
git branch --set-upstream-to=origin/haha test
git push
出现如下信息:

fatal: The upstream branch of your current branch does not match
the name of your current branch.  To push to the upstream branch
on the remote, use

    git push origin HEAD:haha

To push to the branch of the same name on the remote, use

    git push origin test

To choose either option permanently, see push.default in 'git help config'.
意思本地分支和远程分支名字不符,

以下为解决方法:
因为在git的全局配置中,有一个push.default属性,其决定了git push操作的默认行为。在Git 2.0之前,这个属性的默认被设为'matching',2.0之后则被更改为了'simple'。

我们可以通过git version确定当前的git版本(如果小于2.0,更新是个更好的选择),通过git config --global push.default 'option'改变push.default的默认行为(或者也可直接编辑~/.gitconfig文件)。

push.default 有以下几个可选值:
nothing, current, upstream, simple, matching

其用途分别为:

    nothing - push操作无效,除非显式指定远程分支,例如git push origin develop(我觉得。。。可以给那些不愿学git的同事配上此项)。

    current - push当前分支到远程同名分支,如果远程同名分支不存在则自动创建同名分支。

    upstream - push当前分支到它的upstream分支上(这一项其实用于经常从本地分支push/pull到同一远程仓库的情景,这种模式叫做central workflow)。

    simple - simple和upstream是相似的,只有一点不同,simple必须保证本地分支和它的远程
    upstream分支同名,否则会拒绝push操作。

    matching - push所有本地和远程两端都存在的同名分支。

因此如果我们使用了git2.0之前的版本,push.default = matching,git push后则会推送当前分支代码到远程分支,而2.0之后,
push.default = simple,如果没有指定当前分支的upstream分支,就会收到上文的fatal提示。

所以git config --global push.default upstream
之后编辑 add commit之后可以直接git push了。

比较建议还是远端和本地分支同名。

转载于:https://www.cnblogs.com/idyllcheung/p/10651092.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值