问题
I have setup the push.default
option to simple
in my git config, because I think it makes more sense so that I don't create unwanted branches on my remote repository if I push something inadvertendly.
However, sometimes, I know that this push is going to create a new branch in the remote, so I'd like to tell git that for this specific command, I'm willing to change the push.default config to current
(so that it creates a branch of the same name as the one I'm currently in), but only for that command.
Is they a way to do this using git ? Or should I just create a bash alias ?
回答1:
You can try the -c option of the git command:
git -c "push.default=current" push -u origin newBranch
Using:
-c <name>=<value>
Pass a configuration parameter to the command. The value given will override values from configuration files.
The<name>
is expected in the same format as listed by git config (subkeys separated by dots).
回答2:
There are ways to do what you want. A possibility is to do what is suggested by VonC.
However, I think the good policy is that if you need that branch in the remote, you should create it. Do not force the creation of branches from outside of the repository that is suppouse to be shared with more developers.
What is more, it is possible that you cannot have permission to create the branch in the remote and you have to ask for permission to the administrator of that repository.
来源:https://stackoverflow.com/questions/31648939/is-they-a-way-to-set-push-default-to-current-only-for-the-current-push