Quick answer is this shell function to be put in your ~/.profile
. An explanation follows.
git(){(umask 0022; command git "$@")}
A umask is property of a process. It is inherited from the parent process and can be changed from inside later. The command to change umask is usually named umask too.
Git has no configuration option for setting its umask, it does not change its umask after it is executed. You have to set Git's umask from outside, let it be inherited from parent process (usually a shell).
Mmm, you seem to dislike the idea that anything except git has changed umask. So let's change it just when executing git
.
When a shell executes a line, it takes the first word on the line and tries to find a function of that name. Only if there is none, it tries to locate a command of that name in PATH
. The function I've written above is named git
, therefore any direct invocation of git
now executes it instead of the git
command.
The function executes a subshell, changes its umask and executes the git
command from inside the subshell. After Git finishes its work, the subshell also exits and the original shell instance will still have the original umask.
However, the function also shows how to bypass itself. If you call git
via command git
or even /usr/bin/git
, the function won't be called. For any decent use this is good enough, though.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…