In this article, we’ll explore Git settings that enhance performance and usability.
All the configurations mentioned in this article should be added to the ~/.gitconfig
file. This file follows the INI format, with [sections]
defining categories and variables = values
specifying settings.
Performance tuning
[pack]
threads = 0
windowMemory = 5g
packSizeLimit = 2g
Code language: plaintext (plaintext)
threads = 0
: Configures Git to auto-detect the number of CPUs and set the number of threads accordingly.windowMemory = 5g
: Allocates up to 5GB as the amount of memory consumed by each thread in git-pack-objects for pack window memory when no limit is specified on the command line. This enhances Git’s efficiency for large repositories.packSizeLimit = 2g
: The packSizeLimit configuration in Git determines the maximum size of a packfile that Git will generate. A packfile is a file that contains a collection of objects, such as commits, trees, and blobs, in a compressed format.
Garbage collection
[gc]
auto = 8000
auto = 8000
: Automatically triggers garbage collection when the number of loose objects exceeds 8000, optimizing repository storage and performance. The default value is 6700.
Core configurations
[core]
whitespace = space-before-tab,trailing-space
preloadindex = true
Code language: plaintext (plaintext)
whitespace = space-before-tab,trailing-space
Configures whitespace handling.preloadindex = true
Preloads the index into memory for improved performance when running Git commands like status and diff. Setting this to true will make Git load the index into memory early in the execution of commands. This can lead to performance improvements for operations that involve the index, especially in repositories with a large number of files..
Merge and pull settings
[merge]
ff = only
[pull]
ff = only
Code language: plaintext (plaintext)
This setting enforce fast-forward merges, preventing unnecessary merge commits and maintaining a linear commit history.
Enhanced diffing
[diff]
tool = vimdiff
Code language: plaintext (plaintext)
This setting uses vimdiff
as the default diff tool when git difftool
is executed.
Rerere (Reuse Recorded Resolution)
[rerere]
enabled = 1
Code language: plaintext (plaintext)
Enables automatic resolution of previously encountered merge conflicts, reducing the effort required for repeated merges.
Push behavior
[push]
default = current
autoSetupRemote = true
Code language: plaintext (plaintext)
default = current
This configuration automatically pushes the current branch, which helps prevent the error: “fatal: The current branch BRANCH has no upstream branch.” When this setting is in place, Git will push the current branch to the remote, assuming the branch has an upstream set.autoSetupRemote = true
This setting automatically sets up remote tracking for new branches, eliminating the need to manually rungit branch --set-upstream-to
after creating a new branch. It automates the process of linking local branches to their corresponding remote branches. This is useful for users who frequently create new branches, as it reduces the need for repetitive configuration.
Aliases
Here are aliases that abbreviate common Git commands:
[alias]
up = pull --rebase --autostash
s = show
cia = commit -a
rc = rebase --continue
amend = commit --amend
commend = commit --amend --no-edit
p = push
pf = push --force
a = add
aa = add -A
st = status -s
co = checkout
b = branch
rh = reset --hard HEAD
pl = pull
d = diff HEAD
dc = diff --cached
dt = difftool
dw = diff --color-words HEAD
sw = show --color-words
l = log
ls = log --pretty=format:"%C(yellow)%h\ %ad%Cred%d\ %Creset%s%Cblue\ [%cn]" --decorate --date=short
logs = log --show-signature --stat
lp = log -p
chp = cherry-pick
chpa = cherry-pick --abort
chpc = cherry-pick --continue
chpq = cherry-pick --quit
chps = cherry-pick --skip
Code language: plaintext (plaintext)
Conclusion
This Git configuration enhances usability, improves performance, and simplifies repository management through thoughtful settings and powerful aliases.