“git Push”的默认行为 没有指定分支
我使用以下命令推送到我的远程分支:
git push origin sandbox
如果我说
git push origin
这也会推送我其他分支中的更改,还是只更新我当前的分支? 我有三个分支:master
、生产
和sandbox
。
git push
文档对此不是很清楚,所以我想澄清这一点。
以下 git push 命令具体更新哪些分支和遥控器?
git push
git push origin
上面的origin
是一个远程。
我知道 git push [remote] [branch] 只会将该分支推送到远程。
I use the following command to push to my remote branch:
git push origin sandbox
If I say
git push origin
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
.
The git push
documentation is not very clear about this, so I'd like to clarify this for good.
Which branches and remotes do the following git push
commands update exactly?
git push
git push origin
origin
above is a remote.
I understand that git push [remote] [branch]
will push only that branch to the remote.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
您可以在
.gitconfig
中更改默认行为,例如:要检查当前设置,请运行:
You can change that default behavior in your
.gitconfig
, for example:To check the current settings, run:
git Push 会尝试将所有本地分支推送到远程服务器,这可能是您不想要的。 我有几个方便的设置来处理这个问题:
适当地别名“gpull”和“gpush”:
在我的〜/.bash_profile中
因此,执行“gpush”或“gpull”将只推送我的“当前打开”分支。
A git push will try and push all local branches to the remote server, this is likely what you do not want. I have a couple of conveniences setup to deal with this:
Alias "gpull" and "gpush" appropriately:
In my ~/.bash_profile
Thus, executing "gpush" or "gpull" will push just my "currently on" branch.
我更喜欢创建 git-XXX 脚本,而不是使用别名,这样我就可以更轻松地对它们进行源代码控制(我们的开发人员在此类事情的路径上都有一个特定的源代码控制目录)。
此脚本(称为 git-setpush )会将
remote.origin.push 值的配置值设置为仅推送当前分支的值:
请注意,正如我们所见使用
Gerrit
,它将目标设置为refs/ for/XXX
推入审核分支。 它还假设 origin 是您的远程名称。在使用它签出分支后调用它
显然可以适应也进行签出,但我喜欢脚本 做一件事并做好
Rather than using aliases, I prefer creating git-XXX scripts so I can source control them more easily (our devs all have a certain source controlled dir on their path for this type of thing).
This script (called
git-setpush
) will set the config value forremote.origin.push
value to something that will only push the current branch:note, as we're using
Gerrit
, it sets the target torefs/for/XXX
to push into a review branch. It also assumes origin is your remote name.Invoke it after checking out a branch with
It could obviously be adapted to also do the checkout, but I like scripts to do one thing and do it well
git
中的新配置2.37.0
运行以设置自动设置远程,而不是更改
它与推送配合良好的推送默认行为。默认是
简单
,上游
参考:答案
推文
文档
提交
New config in
git
2.37.0
Run to set auto setup remote instead of changing the push default behavior
it works well with push.default is to
simple
,upstream
References: answer
tweet
docs
commit
我已将以下函数添加到 .bashrc 文件中以自动执行这些任务。 它执行 git push/git pull + 当前分支的名称。
I have added the following functions into my .bashrc file to automate these tasks. It does git push/git pull + name of current branch.
我只是将其放入我的 .gitconfig 别名部分,并且喜欢它的工作原理:
将使用 git pub 或另一个使用 git pub repo-name 的存储库将当前分支推送到原点。 可口。
I just put this in my .gitconfig aliases section and love how it works:
Will push the current branch to origin with
git pub
or another repo withgit pub repo-name
. Tasty.您可以通过在 git 配置中设置 push.default 来控制默认行为。 来自 git-config(1) 文档 :
定义如果命令行上没有给出 refspec、远程中没有配置 refspec、并且命令行上给出的任何选项都没有暗示 refspec,则 git Push 应采取的操作。 可能的值为:
nothing
:不推送任何内容matching
:(Git 2.0之前默认)推送所有匹配的分支两端具有相同名称的所有分支都被视为匹配。
upstream
:将当前分支推送到其上游分支(tracking
是上游的已弃用同义词)current
:将当前分支推送到同名分支simple
:(Git 1.7.11 中新增,自 Git 2.0 起默认)与上游类似,但拒绝如果上游分支名称与本地分支名称不同,则推送这是最安全的选择,非常适合初学者。
命令行示例:
查看当前配置:
设置新配置:
You can control the default behavior by setting push.default in your git config. From the git-config(1) documentation:
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
: do not push anythingmatching
: (default before Git 2.0) push all matching branchesAll branches having the same name in both ends are considered to be matching.
upstream
: push the current branch to its upstream branch (tracking
is a deprecated synonym for upstream)current
: push the current branch to a branch of the same namesimple
: (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 oneThis is the safest option and is well-suited for beginners.
Command line examples:
To view the current configuration:
To set a new configuration:
您可以使用push.default为您的git设置默认行为
,或者如果您有许多存储库并且希望所有存储库都相同,则
此设置中的当前意味着默认情况下您将仅推送当前分支 当你执行 git Push
其他选项有:
更新 - 新方法
从 Git 1.7.11 开始,执行以下操作:
这是引入的新设置,其工作方式与当前分支相同,并将默认为 git据传言,从 v 2.0 开始
You can set up default behavior for your git with push.default
or if you have many repositories and want the same for all then
The current in this setup means that by default you will only push the current branch when you do git push
Other options are:
UPDATE - NEW WAY TO DO THIS
As of Git 1.7.11 do the following:
This is a new setting introduced that works in the same way as current, and will be made default to git from v 2.0 according to rumors
您可以使用命令推送当前分支
(取自此处)
You can push current branch with command
(took from here)
(2012 年 3 月)
注意:默认的“
匹配
”政策可能很快就会改变(有时在 git1.7.10+ 之后):
请参阅“请讨论:当你不说要推送什么时,“git Push”应该做什么?"
http://thread.gmane.org/gmane.comp.version-control.git/192547/focus=192694
(March 2012)
Beware: that default "
matching
" policy might change soon(sometimes after git1.7.10+):
See "Please discuss: what "git push" should do when you do not say what to push?"
http://thread.gmane.org/gmane.comp.version-control.git/192547/focus=192694
以下是关于 Git Push 的非常方便且有用的信息:
Git Push:只是提示
git Push 最常见的用途是将本地更改推送到公共上游存储库。 假设上游是一个名为“origin”的远程(如果您的存储库是克隆,则为默认远程名称),并且要更新的分支名为“master”(默认分支名称),这是通过以下方式完成的: < code>git push origin master
git Push origin
会将所有本地分支的更改推送到远程 origin 的匹配分支。git push origin master
会将本地 master 分支的更改推送到远程 master 分支。git push origin master:staging 会将本地 master 分支的更改推送到远程 staging 分支(如果存在)。
Here is a very handy and helpful information about Git Push:
Git Push: Just the Tip
The most common use of git push is to push your local changes to your public upstream repository. Assuming that the upstream is a remote named "origin" (the default remote name if your repository is a clone) and the branch to be updated to/from is named "master" (the default branch name), this is done with:
git push origin master
git push origin
will push changes from all local branches to matching branches the origin remote.git push origin master
will push changes from the local master branch to the remote master branch.git push origin master:staging
will push changes from the local master branch to the remote staging branch if it exists.git push origin
将推送在origin
处具有匹配远程分支的本地分支上的所有更改。来自
git-push< 的示例部分/code> 手册页
git push origin
will push all changes on the local branches that have matching remote branches atorigin
As forgit push
From the Examples section of the
git-push
man page