“git push"的默认行为没有指定分支 [英] Default behavior of "git push" without a branch specified

查看:52
本文介绍了“git push"的默认行为没有指定分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令推送到我的远程分支:

I use the following command to push to my remote branch:

git push origin sandbox

如果我说

git push origin

这是否也会在我的其他分支中推送更改,还是只更新我当前的分支?我有三个分支:masterproductionsandbox.

does that push changes in my other branches too, or does it only update my current branch? I have three branches: master, production and sandbox.

git push 文档对此不是很清楚,所以我想澄清一下.

The git push documentation is not very clear about this, so I'd like to clarify this for good.

以下 git push 命令会准确更新哪些分支和远程?

Which branches and remotes do the following git push commands update exactly?

git push 
git push origin

origin 上面是一个遥控器.

我知道 git push [remote] [branch] 只会将该分支推送到远程.

I understand that git push [remote] [branch] will push only that branch to the remote.

推荐答案

您可以通过在 git 配置中设置 push.default 来控制默认行为.来自 git-config(1) 文档:

You can control the default behavior by setting push.default in your git config. From the git-config(1) documentation:

push.default

定义 git push 应该采取的操作,如果命令行上没有给出 refspec,远程没有配置 refspec,并且命令行上给出的任何选项都没有暗示任何 refspec.可能的值为:

Defines the action git push should take if no refspec is given on the command line, no refspec is configured in the remote, and no refspec is implied by any of the options given on the command line. Possible values are:

  • nothing:不推送任何东西

matching:(Git 2.0 之前的默认值)推送所有匹配的分支

matching: (default before Git 2.0) push all matching branches

两端同名的所有分支都被认为是匹配的.

All branches having the same name in both ends are considered to be matching.

upstream:将当前分支推送到其上游分支(tracking 是不推荐使用的上游同义词)

upstream: push the current branch to its upstream branch (tracking is a deprecated synonym for upstream)

current:将当前分支推送到同名分支

current: push the current branch to a branch of the same name

simple:(Git 1.7.11 新增,自 Git 2.0 起默认)类似于上游,但如果上游分支的名称与本地分支名称不同,则拒绝推送

simple: (new in Git 1.7.11, default since Git 2.0) like upstream, but refuses to push if the upstream branch's name is different from the local one

这是最安全的选择,非常适合初学者.

This is the safest option and is well-suited for beginners.

simple, current 和 upstream 模式适用于那些希望在完成工作后推出单个分支的人,即使其他分支尚未准备好推出

The simple, current and upstream modes are for those who want to push out a single branch after finishing work, even when the other branches are not yet ready to be pushed out

命令行示例:

查看当前配置:

git config --global push.default

设置新配置:

git config --global push.default current

这篇关于“git push"的默认行为没有指定分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆