Administration

If you’re administering a Git repository or need to fix something in a big way, Git provides a number of administrative commands to help you out.

git gc

The git gc command runs “garbage collection” on your repository, removing unnecessary files in your database and packing up the remaining files into a more efficient format.

This command normally runs in the background for you, though you can manually run it if you wish. We go over some examples of this in ch10-git-internals.html.

git fsck

The git fsck command is used to check the internal database for problems or inconsistencies.

We only quickly use this once in ch10-git-internals.html to search for dangling objects.

git reflog

The git reflog command goes through a log of where all the heads of your branches have been as you work to find commits you may have lost through rewriting histories.

We cover this command mainly in ch07-git-tools.html, where we show normal usage to and how to use git log -g to view the same information with git log output.

We also go through a practical example of recovering such a lost branch in ch10-git-internals.html.

git filter-branch

The git filter-branch command is used to rewrite loads of commits according to certain patterns, like removing a file everywhere or filtering the entire repository down to a single subdirectory for extracting a project.

In ch07-git-tools.html we explain the command and explore several different options such as --commit-filter, --subdirectory-filter and --tree-filter.

In ch09-git-and-other-systems.html we use it to fix up imported external repositories.