| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 1 | git-gc(1) |
| 2 | ========= |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | git-gc - Cleanup unnecessary files and optimize the local repository |
| 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
| Junio C Hamano | 15567bc | 2011-07-23 00:51:59 | [diff] [blame] | 11 | [verse] |
| Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 12 | 'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [--force] [--keep-largest-pack] |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 13 | |
| 14 | DESCRIPTION |
| 15 | ----------- |
| 16 | Runs a number of housekeeping tasks within the current repository, |
| 17 | such as compressing file revisions (to reduce disk space and increase |
| Junio C Hamano | 85151f3 | 2018-04-10 00:52:26 | [diff] [blame] | 18 | performance), removing unreachable objects which may have been |
| 19 | created from prior invocations of 'git add', packing refs, pruning |
| Junio C Hamano | a4df8ed | 2018-10-26 06:37:13 | [diff] [blame] | 20 | reflog, rerere metadata or stale working trees. May also update ancillary |
| 21 | indexes such as the commit-graph. |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 22 | |
| 23 | Users are encouraged to run this task on a regular basis within |
| 24 | each repository to maintain good disk space utilization and good |
| Junio C Hamano | d04b60c | 2008-03-20 08:46:04 | [diff] [blame] | 25 | operating performance. |
| 26 | |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 27 | Some git commands may automatically run 'git gc'; see the `--auto` flag |
| Junio C Hamano | d04b60c | 2008-03-20 08:46:04 | [diff] [blame] | 28 | below for details. If you know what you're doing and all you want is to |
| 29 | disable this behavior permanently without further considerations, just do: |
| 30 | |
| 31 | ---------------------- |
| 32 | $ git config --global gc.auto 0 |
| 33 | ---------------------- |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 34 | |
| Junio C Hamano | f65d928 | 2007-01-22 09:00:13 | [diff] [blame] | 35 | OPTIONS |
| 36 | ------- |
| 37 | |
| Junio C Hamano | f2ce297 | 2007-05-20 19:12:09 | [diff] [blame] | 38 | --aggressive:: |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 39 | Usually 'git gc' runs very quickly while providing good disk |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 40 | space utilization and performance. This option will cause |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 41 | 'git gc' to more aggressively optimize the repository at the expense |
| Junio C Hamano | f2ce297 | 2007-05-20 19:12:09 | [diff] [blame] | 42 | of taking much more time. The effects of this optimization are |
| Junio C Hamano | 679d22d | 2007-06-02 21:13:44 | [diff] [blame] | 43 | persistent, so this option only needs to be used occasionally; every |
| Junio C Hamano | f2ce297 | 2007-05-20 19:12:09 | [diff] [blame] | 44 | few hundred changesets or so. |
| Junio C Hamano | f65d928 | 2007-01-22 09:00:13 | [diff] [blame] | 45 | |
| Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 46 | --auto:: |
| Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 47 | With this option, 'git gc' checks whether any housekeeping is |
| Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 48 | required; if not, it exits without performing any work. |
| 49 | Some git commands run `git gc --auto` after performing |
| Junio C Hamano | 85151f3 | 2018-04-10 00:52:26 | [diff] [blame] | 50 | operations that could create many loose objects. Housekeeping |
| 51 | is required if there are too many loose objects or too many |
| 52 | packs in the repository. |
| Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 53 | + |
| Junio C Hamano | 85151f3 | 2018-04-10 00:52:26 | [diff] [blame] | 54 | If the number of loose objects exceeds the value of the `gc.auto` |
| 55 | configuration variable, then all loose objects are combined into a |
| 56 | single pack using `git repack -d -l`. Setting the value of `gc.auto` |
| 57 | to 0 disables automatic packing of loose objects. |
| Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 58 | + |
| Junio C Hamano | 322c624 | 2015-03-23 21:32:46 | [diff] [blame] | 59 | If the number of packs exceeds the value of `gc.autoPackLimit`, |
| Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 60 | then existing packs (except those marked with a `.keep` file |
| 61 | or over `gc.bigPackThreshold` limit) |
| Junio C Hamano | 764a667 | 2007-10-23 01:23:31 | [diff] [blame] | 62 | are consolidated into a single pack by using the `-A` option of |
| Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 63 | 'git repack'. |
| 64 | If the amount of memory is estimated not enough for `git repack` to |
| 65 | run smoothly and `gc.bigPackThreshold` is not set, the largest |
| 66 | pack will also be excluded (this is the equivalent of running `git gc` |
| 67 | with `--keep-base-pack`). |
| 68 | Setting `gc.autoPackLimit` to 0 disables automatic consolidation of |
| 69 | packs. |
| Junio C Hamano | 85151f3 | 2018-04-10 00:52:26 | [diff] [blame] | 70 | + |
| 71 | If houskeeping is required due to many loose objects or packs, all |
| 72 | other housekeeping tasks (e.g. rerere, working trees, reflog...) will |
| 73 | be performed as well. |
| 74 | |
| Junio C Hamano | 1b50ce9 | 2007-10-03 12:05:53 | [diff] [blame] | 75 | |
| Junio C Hamano | 8bc410e | 2009-02-15 10:38:19 | [diff] [blame] | 76 | --prune=<date>:: |
| 77 | Prune loose objects older than date (default is 2 weeks ago, |
| Junio C Hamano | c710296 | 2013-05-29 23:57:17 | [diff] [blame] | 78 | overridable by the config variable `gc.pruneExpire`). |
| Junio C Hamano | decc731 | 2019-03-11 09:02:54 | [diff] [blame^] | 79 | --prune=now prunes loose objects regardless of their age and |
| Junio C Hamano | 56ace3d | 2017-01-10 23:43:41 | [diff] [blame] | 80 | increases the risk of corruption if another process is writing to |
| 81 | the repository concurrently; see "NOTES" below. --prune is on by |
| 82 | default. |
| Junio C Hamano | 8bc410e | 2009-02-15 10:38:19 | [diff] [blame] | 83 | |
| 84 | --no-prune:: |
| 85 | Do not prune any loose objects. |
| 86 | |
| Junio C Hamano | 69a9858 | 2008-03-01 18:42:18 | [diff] [blame] | 87 | --quiet:: |
| 88 | Suppress all progress reports. |
| 89 | |
| Junio C Hamano | 535ed7a | 2013-09-04 20:35:57 | [diff] [blame] | 90 | --force:: |
| 91 | Force `git gc` to run even if there may be another `git gc` |
| 92 | instance running on this repository. |
| 93 | |
| Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 94 | --keep-largest-pack:: |
| 95 | All packs except the largest pack and those marked with a |
| 96 | `.keep` files are consolidated into a single pack. When this |
| 97 | option is used, `gc.bigPackThreshold` is ignored. |
| 98 | |
| 99 | CONFIGURATION |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 100 | ------------- |
| 101 | |
| Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 102 | The optional configuration variable `gc.reflogExpire` can be |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 103 | set to indicate how long historical entries within each branch's |
| 104 | reflog should remain available in this repository. The setting is |
| 105 | expressed as a length of time, for example '90 days' or '3 months'. |
| 106 | It defaults to '90 days'. |
| 107 | |
| Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 108 | The optional configuration variable `gc.reflogExpireUnreachable` |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 109 | can be set to indicate how long historical reflog entries which |
| 110 | are not part of the current branch should remain available in |
| 111 | this repository. These types of entries are generally created as |
| Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 112 | a result of using `git commit --amend` or `git rebase` and are the |
| Junio C Hamano | f9771f6 | 2007-01-17 17:42:30 | [diff] [blame] | 113 | commits prior to the amend or rebase occurring. Since these changes |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 114 | are not part of the current project most users will want to expire |
| 115 | them sooner. This option defaults to '30 days'. |
| 116 | |
| Junio C Hamano | cc7636a | 2010-05-21 14:57:53 | [diff] [blame] | 117 | The above two configuration variables can be given to a pattern. For |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 118 | example, this sets non-default expiry values only to remote-tracking |
| Junio C Hamano | cc7636a | 2010-05-21 14:57:53 | [diff] [blame] | 119 | branches: |
| 120 | |
| 121 | ------------ |
| 122 | [gc "refs/remotes/*"] |
| 123 | reflogExpire = never |
| Junio C Hamano | 322c624 | 2015-03-23 21:32:46 | [diff] [blame] | 124 | reflogExpireUnreachable = 3 days |
| Junio C Hamano | cc7636a | 2010-05-21 14:57:53 | [diff] [blame] | 125 | ------------ |
| 126 | |
| Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 127 | The optional configuration variable `gc.rerereResolved` indicates |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 128 | how long records of conflicted merge you resolved earlier are |
| 129 | kept. This defaults to 60 days. |
| 130 | |
| Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 131 | The optional configuration variable `gc.rerereUnresolved` indicates |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 132 | how long records of conflicted merge you have not resolved are |
| 133 | kept. This defaults to 15 days. |
| 134 | |
| Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 135 | The optional configuration variable `gc.packRefs` determines if |
| Junio C Hamano | cdd1c33 | 2010-12-20 10:08:00 | [diff] [blame] | 136 | 'git gc' runs 'git pack-refs'. This can be set to "notbare" to enable |
| Junio C Hamano | e77b015 | 2008-01-12 06:44:17 | [diff] [blame] | 137 | it within all non-bare repos or it can be set to a boolean value. |
| 138 | This defaults to true. |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 139 | |
| Junio C Hamano | ace33e4 | 2019-01-18 23:16:05 | [diff] [blame] | 140 | The optional configuration variable `gc.writeCommitGraph` determines if |
| Junio C Hamano | f09b7cd | 2018-08-02 23:01:45 | [diff] [blame] | 141 | 'git gc' should run 'git commit-graph write'. This can be set to a |
| 142 | boolean value. This defaults to false. |
| 143 | |
| Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 144 | The optional configuration variable `gc.aggressiveWindow` controls how |
| Junio C Hamano | f2ce297 | 2007-05-20 19:12:09 | [diff] [blame] | 145 | much time is spent optimizing the delta compression of the objects in |
| 146 | the repository when the --aggressive option is specified. The larger |
| 147 | the value, the more time is spent optimizing the delta compression. See |
| Junio C Hamano | ccb8252 | 2018-05-08 07:52:09 | [diff] [blame] | 148 | the documentation for the --window option in linkgit:git-repack[1] for |
| Junio C Hamano | ae4a8f3 | 2009-10-04 09:54:54 | [diff] [blame] | 149 | more details. This defaults to 250. |
| Junio C Hamano | f2ce297 | 2007-05-20 19:12:09 | [diff] [blame] | 150 | |
| Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 151 | Similarly, the optional configuration variable `gc.aggressiveDepth` |
| Junio C Hamano | fa0dac3 | 2017-02-24 19:02:55 | [diff] [blame] | 152 | controls --depth option in linkgit:git-repack[1]. This defaults to 50. |
| Junio C Hamano | 624dd4c | 2014-04-03 21:56:30 | [diff] [blame] | 153 | |
| Junio C Hamano | 042f214 | 2016-06-27 18:05:05 | [diff] [blame] | 154 | The optional configuration variable `gc.pruneExpire` controls how old |
| Junio C Hamano | 09a926d | 2008-03-13 07:55:29 | [diff] [blame] | 155 | the unreferenced loose objects have to be before they are pruned. The |
| 156 | default is "2 weeks ago". |
| 157 | |
| Junio C Hamano | 85151f3 | 2018-04-10 00:52:26 | [diff] [blame] | 158 | Optional configuration variable `gc.worktreePruneExpire` controls how |
| 159 | old a stale working tree should be before `git worktree prune` deletes |
| 160 | it. Default is "3 months ago". |
| 161 | |
| Junio C Hamano | 2f102bb | 2008-04-26 02:23:37 | [diff] [blame] | 162 | |
| Junio C Hamano | b9d9d90 | 2018-05-23 07:07:42 | [diff] [blame] | 163 | NOTES |
| Junio C Hamano | 2f102bb | 2008-04-26 02:23:37 | [diff] [blame] | 164 | ----- |
| 165 | |
| Junio C Hamano | 56ace3d | 2017-01-10 23:43:41 | [diff] [blame] | 166 | 'git gc' tries very hard not to delete objects that are referenced |
| 167 | anywhere in your repository. In |
| Junio C Hamano | 2f102bb | 2008-04-26 02:23:37 | [diff] [blame] | 168 | particular, it will keep not only objects referenced by your current set |
| Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 169 | of branches and tags, but also objects referenced by the index, |
| 170 | remote-tracking branches, refs saved by 'git filter-branch' in |
| Junio C Hamano | 4232bc4 | 2009-10-20 07:49:31 | [diff] [blame] | 171 | refs/original/, or reflogs (which may reference commits in branches |
| Junio C Hamano | 2f102bb | 2008-04-26 02:23:37 | [diff] [blame] | 172 | that were later amended or rewound). |
| Junio C Hamano | 56ace3d | 2017-01-10 23:43:41 | [diff] [blame] | 173 | If you are expecting some objects to be deleted and they aren't, check |
| Junio C Hamano | 2f102bb | 2008-04-26 02:23:37 | [diff] [blame] | 174 | all of those locations and decide whether it makes sense in your case to |
| 175 | remove those references. |
| 176 | |
| Junio C Hamano | 56ace3d | 2017-01-10 23:43:41 | [diff] [blame] | 177 | On the other hand, when 'git gc' runs concurrently with another process, |
| 178 | there is a risk of it deleting an object that the other process is using |
| 179 | but hasn't created a reference to. This may just cause the other process |
| 180 | to fail or may corrupt the repository if the other process later adds a |
| 181 | reference to the deleted object. Git has two features that significantly |
| 182 | mitigate this problem: |
| 183 | |
| 184 | . Any object with modification time newer than the `--prune` date is kept, |
| 185 | along with everything reachable from it. |
| 186 | |
| 187 | . Most operations that add an object to the database update the |
| 188 | modification time of the object if it is already present so that #1 |
| 189 | applies. |
| 190 | |
| 191 | However, these features fall short of a complete solution, so users who |
| 192 | run commands concurrently have to live with some risk of corruption (which |
| 193 | seems to be low in practice) unless they turn off automatic garbage |
| 194 | collection with 'git config gc.auto 0'. |
| 195 | |
| Junio C Hamano | 3e3aa81 | 2010-07-05 23:25:23 | [diff] [blame] | 196 | HOOKS |
| 197 | ----- |
| 198 | |
| 199 | The 'git gc --auto' command will run the 'pre-auto-gc' hook. See |
| 200 | linkgit:githooks[5] for more information. |
| 201 | |
| 202 | |
| Junio C Hamano | 9049d91 | 2008-05-29 02:09:50 | [diff] [blame] | 203 | SEE ALSO |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 204 | -------- |
| Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 205 | linkgit:git-prune[1] |
| 206 | linkgit:git-reflog[1] |
| 207 | linkgit:git-repack[1] |
| 208 | linkgit:git-rerere[1] |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 209 | |
| Junio C Hamano | 5229946 | 2006-12-28 00:59:38 | [diff] [blame] | 210 | GIT |
| 211 | --- |
| Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 212 | Part of the linkgit:git[1] suite |