<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<article lang="en" id="git-gc(1)">
<articleinfo>
    <title>git-gc(1)</title>
        <indexterm>
                <primary>git-gc(1)</primary>
        </indexterm>
</articleinfo>
<simplesect id="_name">
<title>NAME</title>
<simpara>git-gc - Cleanup unnecessary files and optimize the local repository</simpara>
</simplesect>
<simplesect id="_synopsis">
<title>SYNOPSIS</title>
<simpara><emphasis>git gc</emphasis> [--aggressive] [--auto] [--quiet]</simpara>
</simplesect>
<simplesect id="_description">
<title>DESCRIPTION</title>
<simpara>Runs a number of housekeeping tasks within the current repository,
such as compressing file revisions (to reduce disk space and increase
performance) and removing unreachable objects which may have been
created from prior invocations of <emphasis>git-add</emphasis>.</simpara>
<simpara>Users are encouraged to run this task on a regular basis within
each repository to maintain good disk space utilization and good
operating performance.</simpara>
<simpara>Some git commands may automatically run <emphasis>git-gc</emphasis>; see the <literal>--auto</literal> flag
below for details. If you know what you&#8217;re doing and all you want is to
disable this behavior permanently without further considerations, just do:</simpara>
<literallayout>$ git config --global gc.auto 0</literallayout>
</simplesect>
<simplesect id="_options">
<title>OPTIONS</title>
<variablelist>
<varlistentry>
<term>
--aggressive
</term>
<listitem>
<simpara>
        Usually <emphasis>git-gc</emphasis> runs very quickly while providing good disk
        space utilization and performance.  This option will cause
        <emphasis>git-gc</emphasis> to more aggressively optimize the repository at the expense
        of taking much more time.  The effects of this optimization are
        persistent, so this option only needs to be used occasionally; every
        few hundred changesets or so.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--auto
</term>
<listitem>
<simpara>
        With this option, <emphasis>git-gc</emphasis> checks whether any housekeeping is
        required; if not, it exits without performing any work.
        Some git commands run <literal>git gc --auto</literal> after performing
        operations that could create many loose objects.
</simpara>
<simpara>Housekeeping is required if there are too many loose objects or
too many packs in the repository. If the number of loose objects
exceeds the value of the <literal>gc.auto</literal> configuration variable, then
all loose objects are combined into a single pack using
<emphasis>git-repack -d -l</emphasis>.  Setting the value of <literal>gc.auto</literal> to 0
disables automatic packing of loose objects.</simpara>
<simpara>If the number of packs exceeds the value of <literal>gc.autopacklimit</literal>,
then existing packs (except those marked with a <literal>.keep</literal> file)
are consolidated into a single pack by using the <literal>-A</literal> option of
<emphasis>git-repack</emphasis>. Setting <literal>gc.autopacklimit</literal> to 0 disables
automatic consolidation of packs.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
--quiet
</term>
<listitem>
<simpara>
        Suppress all progress reports.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</simplesect>
<simplesect id="_configuration">
<title>Configuration</title>
<simpara>The optional configuration variable <emphasis>gc.reflogExpire</emphasis> can be
set to indicate how long historical entries within each branch&#8217;s
reflog should remain available in this repository.  The setting is
expressed as a length of time, for example <emphasis>90 days</emphasis> or <emphasis>3 months</emphasis>.
It defaults to <emphasis>90 days</emphasis>.</simpara>
<simpara>The optional configuration variable <emphasis>gc.reflogExpireUnreachable</emphasis>
can be set to indicate how long historical reflog entries which
are not part of the current branch should remain available in
this repository.  These types of entries are generally created as
a result of using <literal>git commit --amend</literal> or <literal>git rebase</literal> and are the
commits prior to the amend or rebase occurring.  Since these changes
are not part of the current project most users will want to expire
them sooner.  This option defaults to <emphasis>30 days</emphasis>.</simpara>
<simpara>The optional configuration variable <emphasis>gc.rerereresolved</emphasis> indicates
how long records of conflicted merge you resolved earlier are
kept.  This defaults to 60 days.</simpara>
<simpara>The optional configuration variable <emphasis>gc.rerereunresolved</emphasis> indicates
how long records of conflicted merge you have not resolved are
kept.  This defaults to 15 days.</simpara>
<simpara>The optional configuration variable <emphasis>gc.packrefs</emphasis> determines if
<emphasis>git-gc</emphasis> runs <emphasis>git-pack-refs</emphasis>. This can be set to "nobare" to enable
it within all non-bare repos or it can be set to a boolean value.
This defaults to true.</simpara>
<simpara>The optional configuration variable <emphasis>gc.aggressiveWindow</emphasis> controls how
much time is spent optimizing the delta compression of the objects in
the repository when the --aggressive option is specified.  The larger
the value, the more time is spent optimizing the delta compression.  See
the documentation for the --window' option in <xref linkend="git-repack(1)"/> for
more details.  This defaults to 10.</simpara>
<simpara>The optional configuration variable <emphasis>gc.pruneExpire</emphasis> controls how old
the unreferenced loose objects have to be before they are pruned.  The
default is "2 weeks ago".</simpara>
</simplesect>
<simplesect id="_notes">
<title>Notes</title>
<simpara><emphasis>git-gc</emphasis> tries very hard to be safe about the garbage it collects. In
particular, it will keep not only objects referenced by your current set
of branches and tags, but also objects referenced by the index, remote
tracking branches, refs saved by <emphasis>git-filter-branch</emphasis> in
refs/original/, or reflogs (which may references commits in branches
that were later amended or rewound).</simpara>
<simpara>If you are expecting some objects to be collected and they aren&#8217;t, check
all of those locations and decide whether it makes sense in your case to
remove those references.</simpara>
</simplesect>
<simplesect id="_see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="git-prune(1)"/>
<xref linkend="git-reflog(1)"/>
<xref linkend="git-repack(1)"/>
<xref linkend="git-rerere(1)"/></simpara>
</simplesect>
<simplesect id="_author">
<title>Author</title>
<simpara>Written by Shawn O. Pearce &lt;<ulink url="mailto:spearce@spearce.org">spearce@spearce.org</ulink>&gt;</simpara>
</simplesect>
<simplesect id="_git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)"/> suite</simpara>
</simplesect>
</article>
