简体   繁体   English

排除git push的配置引用

[英]Exclude configured refs for git push

When I call git remote show <remote_name> I see below 当我调用git remote show <remote_name>我会在下面看到

  Local branches configured for 'git pull':
    master           merges with remote master
  Local refs configured for 'git push':
    master           pushes to master           (up to date)

How can I exclude configured pushes? 如何排除已配置的推送? so git push from master branch will throw error and only push will be with explicit remote name git push <remote_name> <remote_branch_name> 所以从master分支的git push将抛出错误,只有push将使用显式远程名称git push <remote_name> <remote_branch_name>

If you change your gitconfig of push.default to nothing then you will need to specify <remote_name> and <remote_branch_name> every time on all branches. 如果将push.default的push.default更改为nothing则每次在所有分支上都需要指定<remote_name><remote_branch_name>

git config --global push.default nothing (remove --global for project specific config) git config --global push.default nothing (删除--global for project specific config)

After setting this you should get an error similar to the following when you git push. 设置此项后,您应该在git push时收到类似于以下内容的错误。

fatal: You didn't specify any refspecs to push, and push.default is "nothing". 致命的:你没有指定任何refspecs推,而push.default是“没什么”。

Update: 更新:

If you just want to disable automatic pushing for a specific branch I would just remove the tracking config. 如果您只想禁用特定分支的自动推送,我只需删除跟踪配置。

One way is to edit your project's .git/config and delete the [branch="branchname"] config. 一种方法是编辑项目的.git/config并删除[branch="branchname"]配置。

Or programmatically: git config --unset branch.branchname.remote which removes the remote=remotename part of the branch's config. 或者以编程方式: git config --unset branch.branchname.remote ,它删除分支配置的remote=remotename部分。

Make sure that you don't have a push config for your remote configured: 确保您没有配置远程配置的push配置:

git config --unset remote.<remote_name>.push

Configure push.default to nothing : 配置push.defaultnothing

git config push.default nothing

Unfortunately, it appears that git remote show <remote_name> doesn't appear to take account of the config.push setting (it always assumes 'matching') so Local refs configured for 'git push' will still be listed in the output. 不幸的是,似乎git remote show <remote_name>似乎没有考虑config.push设置(它总是假设'匹配')所以Local refs configured for 'git push'仍然会在输出中列出。

It's not entirely clear what you want, but if you want to disable a bare git push all together, you can do: 它并不完全清楚你想要什么,但是如果你想要一起禁用裸git push ,你可以这样做:

git config --local push.default nothing

This means that the bare git push will assume no default refspec, and you must specify it. 这意味着裸git push将不会采用默认的refspec,您必须指定它。 The only other thing I can think to do is create an alias, and use that for pushing. 我能想到的另一件事就是创建一个别名,然后用它来推送。 So, something like this in your .gitconfig : 所以,你的.gitconfig是这样的:

[aliases]
p = "!_() { cur=$(git symbolic-ref HEAD); if test \"$cur\" = refs/heads/master -a -z \"$1\"; then { echo \"please specify push target\"; exit 1; } ; fi; git push \"$@\" ; }; _"

Then git p would reject pushing when no other command line parameters are specified on the command line when on master. 然后当在主服务器上时,当命令行上没有指定其他命令行参数时, git p将拒绝推送。 Otherwise, it'd use the push default. 否则,它将使用推送默认值。

I believe that's all the flexibility that you can achieve from git right now. 我相信你现在可以通过git实现所有灵活性。 If you need something more, perhaps talking about it on the git list may convince someone to implement a feature for you. 如果你需要更多的东西,或许在git列表上谈论它可能会说服某人为你实现一个功能。 You'll need a compelling use-case though. 但是,你需要一个引人注目的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM