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 configuration 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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Correct a typo in the comment
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch typo
# Changes to be committed:
#	modified:   src/is-one-of.ts
#
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/src/is-one-of.ts b/src/is-one-of.ts
index ce96317cfd92..c89d482908a2 100644
--- a/src/is-one-of.ts
+++ b/src/is-one-of.ts
@@ -14,7 +14,7 @@
  *
  * This makes sense, because when `fruits` is dynamically constructed by the logic of the program,
  * an unmatched element type is not intended and likely an error. However, the third line in the
- * above code snippet would fail to compile if array contains literal types:
+ * above code snippet would fail to compile if `fruits` contains literal types:
  *
  * ```ts
  * const fruits = ["apple", "orange", "grape"] as const;  // or new Set(["apple", "orange", "grape"] as const);

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:

BeforeAfter
Screenshot Without the SettingsScreenshot With the Settings

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.

Blame Color Screenshot

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.