Git is an open source distributed version control system. It is currently the most popular version control system according to various surveys, and has been the core driver of many popular development platforms, such as GitHub, GitLab, Bitbucket, etc.
While Git comes with a decent default configuration, it is far from the full power of Git. In this post, we will walk through some Git user configurations that unleash more power within Git.
Configuration
commit.verbose
git config --global commit.verbose true
Turning
commit.verbose
on
enables Git to show what changes would be committed at the bottom of the commit message. Below is a
sample output after running git commit
:
|
|
Before turning on commit.verbose
, git commit
would not show the highlighted lines (lines
12–24).
diff.colorMoved
git config --global diff.colorMoved default
git config --global diff.colorMovedWS allow-indentation-change
diff.colorMoved
and
diff.colorMovedWS
control how Git displays moved lines when showing diff. Setting diff.Moved
to default
enables
moved line detection. Setting diff.colorMovedWS
to allow-indentaiton-change
to ignore whitespace
in moved line detection. In effect, setting these options makes Git display moved lines differently
from changed lines:
Before | After |
---|---|
column.ui
git config --global column.ui always
column.ui
specifies
whether supported commands, such as git branch
, git tags
, etc. should output in columns. For
example, without the settings above, git branch
would output all branches, one occupying each
line:
$ git branch
branch1
branch2
branch3
* branch4
master
After setting column.ui
to always
, the same command outputs branches in columns:
$ git branch
branch1 branch2 branch3 * branch4 master
This is especially helpful when the number of outputs is large.
blame.coloring
git config --global blame.coloring highlightRecent
blame.coloring
controls the coloring scheme of the output of git blame
. By setting it to highlightRecent
,
recent changes are highlighted. In the example below, the most recent changes are highlighted in
red, while the earlier changes are highlighted in light blue.
fetch.prune
git config --global fetch.prune true
Setting fetch.prune
to
true
removes any remote-tracking references that no longer exist on the remote when fetching. This
includes branches that only existed on remote and were deleted later. By deleting these branches
locally after they are deleted on the remote, Git makes the local repository cleaner.
status.showStash
git config --global showStash true
Setting status.showStash
to true
makes git status
also display stash information. This helps
uncover forgotten stashed changes.
log.follow
git config --global log.follow true
Setting log.follow
to
true
continues listing the history of a single file beyond renaming.
For example, let us consider a file that has been renamed from Changelog-latest.txt
to
Changelog-1.0.txt
in a repository. After setting log.follow
to true
, git log Changelog-1.0.txt
shows changes that have occurred both before and after the renaming. Otherwise,
Git would only show the changes that have occurred after the renaming.
fetch.parallel
git config --global fetch.parallel 0
fetch.parallel
controls the maximal number of fetch operations to be run in parallel at a time. With
fetch.parallel
set to 0
, Git uses a reasonable maximal number and speeds up fetching.
user.useConfigOnly
git config --global user.useConfigOnly true
Setting
user.useConfigOnly
to true
prevents Git from guessing the user’s name and email when they are unspecified. If you use
multiple Git identities, this can be useful to prevent confusion.