Skip to content

Instantly share code, notes, and snippets.

@psenger
Created October 5, 2023 21:14
Show Gist options
  • Select an option

  • Save psenger/69372479993fe84ce57c51e8bfc6e9c5 to your computer and use it in GitHub Desktop.

Select an option

Save psenger/69372479993fe84ce57c51e8bfc6e9c5 to your computer and use it in GitHub Desktop.
[Clean Up Local Git] #git

Git Cleanup

Cleanup unnecessary files and optimize the local repository

Runs a number of housekeeping tasks within the current repository, such as compressing file revisions (to reduce disk space and increase performance), removing unreachable objects which may have been created from prior invocations of git add, packing refs, pruning reflog, rerere metadata or stale working trees. May also update ancillary indexes such as the commit-graph.

When common porcelain operations that create objects are run, they will check whether the repository has grown substantially since the last maintenance, and if so run git gc automatically. See gc.auto below for how to disable this behavior.

Running git gc manually should only be needed when adding objects to a repository without regularly running such porcelain commands, to do a one-off repository optimization, or e.g. to clean up a suboptimal mass-import. See the "PACKFILE OPTIMIZATION" section in git-fast-import(1) for more details on the import case.

$ git gc
Enumerating objects: 3334, done.
Counting objects: 100% (3334/3334), done.
Delta compression using up to 12 threads
Compressing objects: 100% (992/992), done.
Writing objects: 100% (3334/3334), done.
Total 3334 (delta 2003), reused 3315 (delta 1989), pack-reused 0
Enumerating cruft objects: 39, done.
Traversing cruft objects: 39, done.
Counting objects: 100% (39/39), done.
Delta compression using up to 12 threads
Compressing objects: 100% (37/37), done.
Writing objects: 100% (39/39), done.
Total 39 (delta 7), reused 0 (delta 0), pack-reused 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment