Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices for git maintenance?

I'm looking at the git-maintenance manual and is unclear for me how the actual maintenance tasks are performed. To my understanding, once I execute git maintenance run --auto, several tasks are executed in the background. For example, if I perform a git pull, any related maintenance tasks should be executed automatically.

The part I cannot properly comprehend is if these tasks need to be scheduled by myself prior, or the --auto switch does that for me. My goal is to have the following maintenance tasks executed at specified timeline:

  • gc: weekly, default disabled
  • commit-graph: hourly
  • prefetch: hourly
  • loose-objects: daily
  • incremental-repack: daily

I would like to know what are the proper git maintenance commands to properly schedule the above tasks and also to get your input of recommended timelines for each task, they are taken from the manual, except gc, which is disabled by default.

Current ./.git structure, prior running any git maintenance commands:

# git --version
git version 2.30.2

# ls -lah .git
total 303K
drwxr-xr-x  8 root root   13 Dec 27 17:18 .
drwxr-xr-x 11 root root   19 Dec 27 17:18 ..
-rw-r--r--  1 root root   21 Dec 27 17:18 HEAD
drwxr-xr-x  2 root root    2 Dec 27 17:17 branches
-rw-r--r--  1 root root  252 Dec 27 17:18 config
-rw-r--r--  1 root root   73 Dec 27 17:17 description
drwxr-xr-x  2 root root   15 Dec 27 17:17 hooks
-rw-r--r--  1 root root 553K Dec 27 17:18 index
drwxr-xr-x  2 root root    3 Dec 27 17:17 info
drwxr-xr-x  3 root root    4 Dec 27 17:18 logs
drwxr-xr-x  4 root root    4 Dec 27 17:17 objects
-rw-r--r--  1 root root  112 Dec 27 17:18 packed-refs
drwxr-xr-x  5 root root    5 Dec 27 17:18 refs

./git/config [maintenance] section:

[maintenance]
    auto = false
    strategy = incremental

I expected running git maintenance run --auto command to set auto = true, but it is not. Thank you for taking the time to provide an example, how to properly configure the repo maintenance.

like image 839
Floren Avatar asked May 03 '26 07:05

Floren


1 Answers

The question is a bit old, but hopefully this can help others.

If you want to schedule the maintenance tasks you should:

  1. Run git maintenance start, this will create the hourly, daily and weekly tasks. Depending on your os, you can edit those tasks if you want them to be run in specific timings.

  2. Set maintenance strategy: run git config --global maintenance.strategy incremental

    incremental: This setting optimizes for performing small maintenance activities that do not delete any data. This does not schedule the gc task, but runs the prefetch and commit-graph tasks hourly, the loose-objects and incremental-repack tasks daily, and the pack-refs task weekly.

    If you want to set gc weekly you can run git config maintenance.gc.schedule weekly , if you want if for all repos: git config --global maintenance.gc.schedule weekly

  3. Register the repos you want to run maintenance on, by running git maintenance register on your repo.

There are no best practices really, I would say for most cases just stick to the incremental strategy. If you are having issues on your repo it would be wise to investigate and run some tasks more frequently depending on the problem. For big repos with heavy usage you might wanna run the gc daily.

like image 136
mehdixe Avatar answered May 05 '26 21:05

mehdixe