Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safe to run git gc

I have encountered my first request to run git gc. The message I received on my last commit was:

warning: There are too many unreachable loose objects; run 'git prune' to remove them.

and ...

You may also run "git gc" manually. See "git help gc" for more information.

So my question is do I run git gc --aggressive, --auto --prune or --quiet.

Essentially I am concerned that I might lose any commit history or disrupt my master branch in any way?

Any recommendations?

like image 279
Volterony Avatar asked Feb 06 '14 20:02

Volterony


People also ask

When should you not run git gc?

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.

Does git gc run automatically?

Garbage collection is run automatically on several frequently used commands: git pull. git merge. git rebase.

Does Github run git gc?

We run git gc at most once per day, triggered automatically by a push.

Is git prune safe?

Again, these are all implementation details that git gc handles and git prune should not be used standalone. The above command will force expire all entries to the reflog that are older than now. This is a brutal and dangerous command that you should never have to use as casual Git user.


1 Answers

In general, git gc is safe to run. It won't throw away any commits reachable from any named reference. Depending on how you've set the appropriate expiration variable (e.g., gc.pruneexpire, gc.reflogexpire, etc.) it will possibly throw away commits that are only reachable from the reflog, or aren't reachable at all. I let git gc decide when to prune on its own (looking at those expire settings) and usually do a git gc --aggressive. It displays some stats while it's working. If you don't want to see those, then add --quiet.

like image 170
Wolf Avatar answered Sep 22 '22 12:09

Wolf