How to Configure Expiry Objects (Git)

Reginald LynchOctober 30th 2020, 5:01

By default, Git will perform garbage collection on unreferenced objects and clean reflog for entries that are more than 90 days old. For an object to be referenced, something must point to it; a tree, a commit, a tag, a branch, or some of the internal Git bookkeeping, such as stash or reflog. There are three settings that can be used to change this time as follows:

Step 1 : gc.reflogexpire: This is the general setting to know for how long a branch's history is kept in reflog. The default time is 90 days. The setting is a length of time, for example, 10 days, 6 months, and it can be turned completely with the value never. The setting can be set to match a refs pattern by supplying the pattern in the configuration setting. gc.<pattern>.reflogexpire: This pattern can, for example, be /refs/remotes/*,and the expire setting would then only apply for those refs.

git config gc./refs/remote/*.reflogexpire never

Step 2: gc.reflogexpireunreachable: This setting controls how long the reflog entries that are not a part of the current branch history should be available in the repository. The default value is 30 days, and similar to the previous option, it is expressed as a length of time or set to never in order to turn it off. This setting can, as the previous one, be set to match a refs pattern.

git config gc./refs/remote/*.reflogexpireunreachable "2 months"

Step 3 : gc.pruneexpire: This option tells git gc to prune objects older than the value. The default is 2.weeks.ago, and the value can be expressed as a relative date, such as 3.months.ago. To disable the grace period, the value now can be used. To set a non-default expiry date on remote branches only, use the following command:

git config gc.pruneexpire 3.days.ago