As an example, I prefer viewing my Git branches using the flag --sort=committerdate
. Is there a way to edit my .gitconfig
to automatically use that flag?
Is there a general way to pass flags to commands by default?
As an example, I prefer viewing my Git branches using the flag --sort=committerdate
. Is there a way to edit my .gitconfig
to automatically use that flag?
Is there a general way to pass flags to commands by default?
Is there a general way to pass flags to commands by default?
No. Or rather, both no and yes, but it's not what you think, and --sort
for git branch
is not available this way.
There are two ways to do this, one general-purpose and one rather ad hoc. The general purpose method is to use aliases, which can be either shell aliases (the precise syntax for these depends on your shell) or Git aliases (which are defined by Git and hence more predictable here). For instance, you can make an alias br
for branch --sort=committerdate
:
$ git config alias.br "branch --sort=committerdate"
after which git br
runs git branch --sort=committerdate
.
The ad hoc method is per Git command and requires consulting both the documentation for that particular command—e.g., the git log
documentation for git log
—and the git config
documentation. Here you will find that, for instance, the log.decorate
setting controls whether --decorate
is the default, and the color.branch
(not branch.color
) setting controls whether git branch
output is colored by default. The "default default" for some of these defaults is often controlled by yet another setting, so that branch coloring is determined by the first of:
--color
or --no-color
option if specified, orcolor.branch
setting if specified, orcolor.ui
setting if specified, orisatty(1)
function).As it happens, there is no --sort=<key>
control knob, so you are left with aliases as the only option here. Well, that is, unless you add a branch.sort
or sort.branch
setting knob, and convince the Git folks to adopt it! :-)