Exclude configured refs for git push
When I call git remote show <remote_name>
I see below
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>
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.
git config --global push.default nothing
(remove --global for project specific config)
After setting this you should get an error similar to the following when you git push.
fatal: You didn't specify any refspecs to push, and push.default is "nothing".
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.
Or programmatically: git config --unset branch.branchname.remote
which removes the remote=remotename
part of the branch's config.
Make sure that you don't have a push
config for your remote configured:
git config --unset remote.<remote_name>.push
Configure push.default
to nothing
:
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.
It's not entirely clear what you want, but if you want to disable a bare git push
all together, you can do:
git config --local push.default nothing
This means that the bare git push
will assume no default refspec, and you must specify it. 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
:
[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. Otherwise, it'd use the push default.
I believe that's all the flexibility that you can achieve from git right now. If you need something more, perhaps talking about it on the git list may convince someone to implement a feature for you. You'll need a compelling use-case though.
链接地址: http://www.djcxy.com/p/26104.html上一篇: 我如何隐藏“pr”远程分支?
下一篇: 排除git push的配置参考