I want to override certain Git configuration options (in my case http.proxy
) when calling a Git command directly by using command line parameters. Is this possi
As documented in Git 2.23 (Q3 2019), but already available before that, another place where you can override Git configuration option is... git aliases!
See commit 459842e, commit 01991ce (05 Jun 2019) by Denton Liu (Denton-L).
(Merged by Junio C Hamano -- gitster -- in commit 71221f2, 09 Jul 2019)
config/alias.txt
: document alias accepting non-command first wordOne can see that an alias that begins with a non-command first word, such as
loud-rebase = -c commit.verbose=true rebase
, is permitted.
However, this isn't immediately obvious to users as alias instances typically begin with a command.Document the fact that an alias can begin with a non-command first word so that users will be able to discover that this is a feature.
The documentation now includes:
Note that the first word of an alias does not necessarily have to be a command. It can be a command-line option that will be passed into the invocation of
git
.In particular, this is useful when used with
-c
to pass in one-time configurations or-p
to force pagination.For example,
loud-rebase = -c commit.verbose=true rebase
can be defined such that runninggit loud-rebase
would be equivalent togit -c commit.verbose=true rebase
.Also,
ps = -p status
would be a helpful alias sincegit ps
would paginate the output ofgit status
where the original command does not.
For example, I defined:
vonc@vonvb:~/gits/src/git$ git config alias.loud-commit "-c commit.verbose=true commit"
vonc@vonvb:~/gits/src/git$ git loud-commit -a
That gives me:
The diff (red part) would not be present in a commit message editor with a simple git commit -a
.
The alias did not need to start with !git
to call the shell command git
.
It can directly start with a git
command option, like -c
.