Git/Tweaks

From Gentoo Wiki
Jump to:navigation Jump to:search

The devmanual has some good introductory material on gentoo.git settings and best practices but this page aims to document some neat bonus features and config options available in git.

Small files

Tell git to optimize for many small files (https://github.blog/2019-11-03-highlights-from-git-2-24/).

This enables the 'many files' macro which can change meaning depending on the version of git: it's a metasetting. So, if there are future improvements/improved advice on what's best for repositories with many files, you'll automatically pick it up without modifying individual "real" settings.

Run this within a git repository (need to run this, like all the commands here, once per repository):

user $git config feature.manyFiles true

watchman

dev-util/watchman is a tool by Facebook much like app-admin/entr. git ships with hooks that integrate with watchman to speed up commands like git status!

To enable it, first install it:

root #emerge --ask dev-util/watchman

Then run the following within a git repository:

user $cp .git/hooks/fsmonitor-watchman.sample .git/hooks/query-watchman
user $chmod +x .git/hooks/query-watchman
user $git config core.fsmonitor .git/hooks/query-watchman

Maintenance subcommand

git since v2.31 supports the git maintenance subcommand. No longer must users run several commands to keep their repositories in good health.

It has support for cron and since 2.34, it can make use of systemd user services, so there's no excuse not to use it.

user $git maintenance start # sets the needed config options *and* schedules it to run automatically
user $git maintenance run # run it manually as a one-off to get the benefits immediately

Note that it doesn't, as of 2.38.1, add git gc to any scheduled runs. To run it weekly:

user $git config --global maintenance.gc.schedule weekly

For systemd, it may be needed to explicitly run:

user $git maintenance start --scheduler=systemd-timer

Ricing

There are a few additional options that can be set which might help. You should research them first though.

Parallel checkout

This is off by default (for now?) because it doesn't help on rotational media or other slow disks. It is however worth it on SSDs and such.

Read more in the github's git v2.33 roundup or another writeup.

Run the following:

user $git config --global checkout.workers 0

Where the '0' denotes that the number of cores should be used.

Reverse index

This isn't yet enabled by default. See again github's git v2.31 roundup.

user $git config pack.writeReverseIndex true
user $git repack -Ad