{
    "mode": "info",
    "parameter": "git-maintenance",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/git-maintenance/json",
    "generated": "2026-07-11T14:13:06Z",
    "synopsis": "git maintenance run [<options>]",
    "sections": {
        "NAME": {
            "content": "git-maintenance - Run tasks to optimize Git repository data\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "git maintenance run [<options>]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Run tasks to optimize Git repository data, speeding up other Git\ncommands and reducing storage requirements for the repository.\n\nGit commands that add repository data, such as git add or git fetch,\nare optimized for a responsive user experience. These commands do not\ntake time to optimize the Git data, since such optimizations scale with\nthe full size of the repository while these user commands each perform\na relatively small action.\n\nThe git maintenance command provides flexibility for how to optimize\nthe Git repository.\n",
            "subsections": []
        },
        "SUBCOMMANDS": {
            "content": "register\nInitialize Git config values so any scheduled maintenance will\nstart running on this repository. This adds the repository to the\nmaintenance.repo config variable in the current user's global\nconfig and enables some recommended configuration values for\nmaintenance.<task>.schedule. The tasks that are enabled are safe\nfor running in the background without disrupting foreground\nprocesses.\n\nThe register subcommand will also set the maintenance.strategy\nconfig value to incremental, if this value is not previously set.\nThe incremental strategy uses the following schedule for each\nmaintenance task:\n\no   gc: disabled.\n\no   commit-graph: hourly.\n\no   prefetch: hourly.\n\no   loose-objects: daily.\n\no   incremental-repack: daily.\n\ngit maintenance register will also disable foreground maintenance\nby setting maintenance.auto = false in the current repository. This\nconfig setting will remain after a git maintenance unregister\ncommand.\n\nrun\nRun one or more maintenance tasks. If one or more --task options\nare specified, then those tasks are run in that order. Otherwise,\nthe tasks are determined by which maintenance.<task>.enabled config\noptions are true. By default, only maintenance.gc.enabled is true.\n\nstart\nStart running maintenance on the current repository. This performs\nthe same config updates as the register subcommand, then updates\nthe background scheduler to run git maintenance run --scheduled on\nan hourly basis.\n\nstop\nHalt the background maintenance schedule. The current repository is\nnot removed from the list of maintained repositories, in case the\nbackground maintenance is restarted later.\n\nunregister\nRemove the current repository from background maintenance. This\nonly removes the repository from the configured list. It does not\nstop the background maintenance processes from running.\n",
            "subsections": []
        },
        "TASKS": {
            "content": "commit-graph\nThe commit-graph job updates the commit-graph files incrementally,\nthen verifies that the written data is correct. The incremental\nwrite is safe to run alongside concurrent Git processes since it\nwill not expire .graph files that were in the previous\ncommit-graph-chain file. They will be deleted by a later run based\non the expiration delay.\n\nprefetch\nThe prefetch task updates the object directory with the latest\nobjects from all registered remotes. For each remote, a git fetch\ncommand is run. The configured refspec is modified to place all\nrequested refs within refs/prefetch/. Also, tags are not updated.\n\nThis is done to avoid disrupting the remote-tracking branches. The\nend users expect these refs to stay unmoved unless they initiate a\nfetch. With prefetch task, however, the objects necessary to\ncomplete a later real fetch would already be obtained, so the real\nfetch would go faster. In the ideal case, it will just become an\nupdate to a bunch of remote-tracking branches without any object\ntransfer.\n\ngc\nClean up unnecessary files and optimize the local repository. \"GC\"\nstands for \"garbage collection,\" but this task performs many\nsmaller tasks. This task can be expensive for large repositories,\nas it repacks all Git objects into a single pack-file. It can also\nbe disruptive in some situations, as it deletes stale data. See\ngit-gc(1) for more details on garbage collection in Git.\n\nloose-objects\nThe loose-objects job cleans up loose objects and places them into\npack-files. In order to prevent race conditions with concurrent Git\ncommands, it follows a two-step process. First, it deletes any\nloose objects that already exist in a pack-file; concurrent Git\nprocesses will examine the pack-file for the object data instead of\nthe loose object. Second, it creates a new pack-file (starting with\n\"loose-\") containing a batch of loose objects. The batch size is\nlimited to 50 thousand objects to prevent the job from taking too\nlong on a repository with many loose objects. The gc task writes\nunreachable objects as loose objects to be cleaned up by a later\nstep only if they are not re-added to a pack-file; for this reason\nit is not advisable to enable both the loose-objects and gc tasks\nat the same time.\n\nincremental-repack\nThe incremental-repack job repacks the object directory using the\nmulti-pack-index feature. In order to prevent race conditions with\nconcurrent Git commands, it follows a two-step process. First, it\ncalls git multi-pack-index expire to delete pack-files unreferenced\nby the multi-pack-index file. Second, it calls git multi-pack-index\nrepack to select several small pack-files and repack them into a\nbigger one, and then update the multi-pack-index entries that refer\nto the small pack-files to refer to the new pack-file. This\nprepares those small pack-files for deletion upon the next run of\ngit multi-pack-index expire. The selection of the small pack-files\nis such that the expected size of the big pack-file is at least the\nbatch size; see the --batch-size option for the repack subcommand\nin git-multi-pack-index(1). The default batch-size is zero, which\nis a special case that attempts to repack all pack-files into a\nsingle pack-file.\n\npack-refs\nThe pack-refs task collects the loose reference files and collects\nthem into a single file. This speeds up operations that need to\niterate across many references. See git-pack-refs(1) for more\ninformation.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "--auto",
                    "content": "When combined with the run subcommand, run maintenance tasks only\nif certain thresholds are met. For example, the gc task runs when\nthe number of loose objects exceeds the number stored in the\ngc.auto config setting, or when the number of pack-files exceeds\nthe gc.autoPackLimit config setting. Not compatible with the\n--schedule option.\n",
                    "long": "--auto"
                },
                {
                    "name": "--schedule",
                    "content": "When combined with the run subcommand, run maintenance tasks only\nif certain time conditions are met, as specified by the\nmaintenance.<task>.schedule config value for each <task>. This\nconfig value specifies a number of seconds since the last time that\ntask ran, according to the maintenance.<task>.lastRun config value.\nThe tasks that are tested are those provided by the --task=<task>\noption(s) or those with maintenance.<task>.enabled set to true.\n",
                    "long": "--schedule"
                },
                {
                    "name": "--quiet",
                    "content": "Do not report progress or other information over stderr.\n\n--task=<task>\nIf this option is specified one or more times, then only run the\nspecified tasks in the specified order. If no --task=<task>\narguments are specified, then only the tasks with\nmaintenance.<task>.enabled configured as true are considered. See\nthe TASKS section for the list of accepted <task> values.\n\n--scheduler=auto|crontab|systemd-timer|launchctl|schtasks\nWhen combined with the start subcommand, specify the scheduler for\nrunning the hourly, daily and weekly executions of git maintenance\nrun. Possible values for <scheduler> are auto, crontab (POSIX),\nsystemd-timer (Linux), launchctl (macOS), and schtasks (Windows).\nWhen auto is specified, the appropriate platform-specific scheduler\nis used; on Linux, systemd-timer is used if available, otherwise\ncrontab. Default is auto.\n",
                    "long": "--quiet"
                }
            ]
        },
        "TROUBLESHOOTING": {
            "content": "The git maintenance command is designed to simplify the repository\nmaintenance patterns while minimizing user wait time during Git\ncommands. A variety of configuration options are available to allow\ncustomizing this process. The default maintenance options focus on\noperations that complete quickly, even on large repositories.\n\nUsers may find some cases where scheduled maintenance tasks do not run\nas frequently as intended. Each git maintenance run command takes a\nlock on the repository's object database, and this prevents other\nconcurrent git maintenance run commands from running on the same\nrepository. Without this safeguard, competing processes could leave the\nrepository in an unpredictable state.\n\nThe background maintenance schedule runs git maintenance run processes\non an hourly basis. Each run executes the \"hourly\" tasks. At midnight,\nthat process also executes the \"daily\" tasks. At midnight on the first\nday of the week, that process also executes the \"weekly\" tasks. A\nsingle process iterates over each registered repository, performing the\nscheduled tasks for that frequency. Depending on the number of\nregistered repositories and their sizes, this process may take longer\nthan an hour. In this case, multiple git maintenance run commands may\nrun on the same repository at the same time, colliding on the object\ndatabase lock. This results in one of the two tasks not running.\n\nIf you find that some maintenance windows are taking longer than one\nhour to complete, then consider reducing the complexity of your\nmaintenance tasks. For example, the gc task is much slower than the\nincremental-repack task. However, this comes at a cost of a slightly\nlarger object database. Consider moving more expensive tasks to be run\nless frequently.\n\nExpert users may consider scheduling their own maintenance tasks using\na different schedule than is available through git maintenance start\nand Git configuration options. These users should be aware of the\nobject database lock and how concurrent git maintenance run commands\nbehave. Further, the git gc command should not be combined with git\nmaintenance run commands. git gc modifies the object database but does\nnot take the lock in the same way as git maintenance run. If possible,\nuse git maintenance run --task=gc instead of git gc.\n\nThe following sections describe the mechanisms put in place to run\nbackground maintenance by git maintenance start and how to customize\nthem.\n",
            "subsections": []
        },
        "BACKGROUND MAINTENANCE ON POSIX SYSTEMS": {
            "content": "The standard mechanism for scheduling background tasks on POSIX systems\nis cron(8). This tool executes commands based on a given schedule. The\ncurrent list of user-scheduled tasks can be found by running crontab\n-l. The schedule written by git maintenance start is similar to this:\n\n# BEGIN GIT MAINTENANCE SCHEDULE\n# The following schedule was created by Git\n# Any edits made in this region might be\n# replaced in the future by a Git command.\n\n0 1-23 * * * \"/<path>/git\" --exec-path=\"/<path>\" for-each-repo --config=maintenance.repo maintenance run --schedule=hourly\n0 0 * * 1-6 \"/<path>/git\" --exec-path=\"/<path>\" for-each-repo --config=maintenance.repo maintenance run --schedule=daily\n0 0 * * 0 \"/<path>/git\" --exec-path=\"/<path>\" for-each-repo --config=maintenance.repo maintenance run --schedule=weekly\n\n# END GIT MAINTENANCE SCHEDULE\n\nThe comments are used as a region to mark the schedule as written by\nGit. Any modifications within this region will be completely deleted by\ngit maintenance stop or overwritten by git maintenance start.\n\nThe crontab entry specifies the full path of the git executable to\nensure that the executed git command is the same one with which git\nmaintenance start was issued independent of PATH. If the same user runs\ngit maintenance start with multiple Git executables, then only the\nlatest executable is used.\n\nThese commands use git for-each-repo --config=maintenance.repo to run\ngit maintenance run --schedule=<frequency> on each repository listed in\nthe multi-valued maintenance.repo config option. These are typically\nloaded from the user-specific global config. The git maintenance\nprocess then determines which maintenance tasks are configured to run\non each repository with each <frequency> using the\nmaintenance.<task>.schedule config options. These values are loaded\nfrom the global or repository config values.\n\nIf the config values are insufficient to achieve your desired\nbackground maintenance schedule, then you can create your own schedule.\nIf you run crontab -e, then an editor will load with your user-specific\ncron schedule. In that editor, you can add your own schedule lines. You\ncould start by adapting the default schedule listed earlier, or you\ncould read the crontab(5) documentation for advanced scheduling\ntechniques. Please do use the full path and --exec-path techniques from\nthe default schedule to ensure you are executing the correct binaries\nin your schedule.\n",
            "subsections": []
        },
        "BACKGROUND MAINTENANCE ON LINUX SYSTEMD SYSTEMS": {
            "content": "While Linux supports cron, depending on the distribution, cron may be\nan optional package not necessarily installed. On modern Linux\ndistributions, systemd timers are superseding it.\n\nIf user systemd timers are available, they will be used as a\nreplacement of cron.\n\nIn this case, git maintenance start will create user systemd timer\nunits and start the timers. The current list of user-scheduled tasks\ncan be found by running systemctl --user list-timers. The timers\nwritten by git maintenance start are similar to this:\n\n$ systemctl --user list-timers\nNEXT                         LEFT          LAST                         PASSED     UNIT                         ACTIVATES\nThu 2021-04-29 19:00:00 CEST 42min left    Thu 2021-04-29 18:00:11 CEST 17min ago  git-maintenance@hourly.timer git-maintenance@hourly.service\nFri 2021-04-30 00:00:00 CEST 5h 42min left Thu 2021-04-29 00:00:11 CEST 18h ago    git-maintenance@daily.timer  git-maintenance@daily.service\nMon 2021-05-03 00:00:00 CEST 3 days left   Mon 2021-04-26 00:00:11 CEST 3 days ago git-maintenance@weekly.timer git-maintenance@weekly.service\n\nOne timer is registered for each --schedule=<frequency> option.\n\nThe definition of the systemd units can be inspected in the following\nfiles:\n\n~/.config/systemd/user/git-maintenance@.timer\n~/.config/systemd/user/git-maintenance@.service\n~/.config/systemd/user/timers.target.wants/git-maintenance@hourly.timer\n~/.config/systemd/user/timers.target.wants/git-maintenance@daily.timer\n~/.config/systemd/user/timers.target.wants/git-maintenance@weekly.timer\n\ngit maintenance start will overwrite these files and start the timer\nagain with systemctl --user, so any customization should be done by\ncreating a drop-in file, i.e. a .conf suffixed file in the\n~/.config/systemd/user/git-maintenance@.service.d directory.\n\ngit maintenance stop will stop the user systemd timers and delete the\nabove mentioned files.\n\nFor more details, see systemd.timer(5).\n",
            "subsections": []
        },
        "BACKGROUND MAINTENANCE ON MACOS SYSTEMS": {
            "content": "While macOS technically supports cron, using crontab -e requires\nelevated privileges and the executed process does not have a full user\ncontext. Without a full user context, Git and its credential helpers\ncannot access stored credentials, so some maintenance tasks are not\nfunctional.\n\nInstead, git maintenance start interacts with the launchctl tool, which\nis the recommended way to schedule timed jobs in macOS. Scheduling\nmaintenance through git maintenance (start|stop) requires some\nlaunchctl features available only in macOS 10.11 or later.\n\nYour user-specific scheduled tasks are stored as XML-formatted .plist\nfiles in ~/Library/LaunchAgents/. You can see the currently-registered\ntasks using the following command:\n\n$ ls ~/Library/LaunchAgents/org.git-scm.git*\norg.git-scm.git.daily.plist\norg.git-scm.git.hourly.plist\norg.git-scm.git.weekly.plist\n\nOne task is registered for each --schedule=<frequency> option. To\ninspect how the XML format describes each schedule, open one of these\n.plist files in an editor and inspect the <array> element following the\n<key>StartCalendarInterval</key> element.\n\ngit maintenance start will overwrite these files and register the tasks\nagain with launchctl, so any customizations should be done by creating\nyour own .plist files with distinct names. Similarly, the git\nmaintenance stop command will unregister the tasks with launchctl and\ndelete the .plist files.\n\nTo create more advanced customizations to your background tasks, see\nlaunchctl.plist(5) for more information.\n",
            "subsections": []
        },
        "BACKGROUND MAINTENANCE ON WINDOWS SYSTEMS": {
            "content": "Windows does not support cron and instead has its own system for\nscheduling background tasks. The git maintenance start command uses the\nschtasks command to submit tasks to this system. You can inspect all\nbackground tasks using the Task Scheduler application. The tasks added\nby Git have names of the form Git Maintenance (<frequency>). The Task\nScheduler GUI has ways to inspect these tasks, but you can also export\nthe tasks to XML files and view the details there.\n\nNote that since Git is a console application, these background tasks\ncreate a console window visible to the current user. This can be\nchanged manually by selecting the \"Run whether user is logged in or\nnot\" option in Task Scheduler. This change requires a password input,\nwhich is why git maintenance start does not select it by default.\n\nIf you want to customize the background tasks, please rename the tasks\nso future calls to git maintenance (start|stop) do not overwrite your\ncustom tasks.\n",
            "subsections": []
        },
        "GIT": {
            "content": "Part of the git(1) suite\n\nGit 2.34.1                        02/26/2026                GIT-MAINTENANCE(1)",
            "subsections": []
        }
    },
    "summary": "git-maintenance - Run tasks to optimize Git repository data",
    "flags": [
        {
            "flag": "",
            "long": "--auto",
            "arg": null,
            "description": "When combined with the run subcommand, run maintenance tasks only if certain thresholds are met. For example, the gc task runs when the number of loose objects exceeds the number stored in the gc.auto config setting, or when the number of pack-files exceeds the gc.autoPackLimit config setting. Not compatible with the --schedule option."
        },
        {
            "flag": "",
            "long": "--schedule",
            "arg": null,
            "description": "When combined with the run subcommand, run maintenance tasks only if certain time conditions are met, as specified by the maintenance.<task>.schedule config value for each <task>. This config value specifies a number of seconds since the last time that task ran, according to the maintenance.<task>.lastRun config value. The tasks that are tested are those provided by the --task=<task> option(s) or those with maintenance.<task>.enabled set to true."
        },
        {
            "flag": "",
            "long": "--quiet",
            "arg": null,
            "description": "Do not report progress or other information over stderr. --task=<task> If this option is specified one or more times, then only run the specified tasks in the specified order. If no --task=<task> arguments are specified, then only the tasks with maintenance.<task>.enabled configured as true are considered. See the TASKS section for the list of accepted <task> values. --scheduler=auto|crontab|systemd-timer|launchctl|schtasks When combined with the start subcommand, specify the scheduler for running the hourly, daily and weekly executions of git maintenance run. Possible values for <scheduler> are auto, crontab (POSIX), systemd-timer (Linux), launchctl (macOS), and schtasks (Windows). When auto is specified, the appropriate platform-specific scheduler is used; on Linux, systemd-timer is used if available, otherwise crontab. Default is auto."
        }
    ],
    "examples": [],
    "see_also": []
}