{"id":4908,"date":"2011-12-30T00:55:37","date_gmt":"2011-12-29T19:25:37","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=4908"},"modified":"2016-12-19T14:36:45","modified_gmt":"2016-12-19T09:06:45","slug":"git-maintenance","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/git-maintenance\/","title":{"rendered":"GIT Maintenance"},"content":{"rendered":"<p>Since we use git numerous times a day over and over, hence needs maintenance. There are few commands that will help you to keep our git healthy. If you feel that you git has somewhat slowed down, these would do the trick for you.<\/p>\n<p>Since ours is a pretty big project . I run it once a week to make sure my git is healthy.<\/p>\n<p>1.git fsck<\/p>\n<p>This commands helps to identify any corrupted, unreachable (dangling blobs) objects in your database.<br \/>\nExample<\/p>\n<p>[shell]<br \/>\ngit fsck<br \/>\ndangling commit 652424f02c17b5d881158a625f1a34f6039dc231<br \/>\ndangling commit 7e6510c2663530d949ea9fb67900496dcf5cbc4c<br \/>\ndangling commit 177864469ea87564ade9101106d5aa85cceb0d29<br \/>\ndangling commit 848665007bc412910b68dc3e528e74c23ce1f165<br \/>\ndangling blob dfa6756511b525996946de84fa7f67b6f9a0d32f<br \/>\ndangling blob e7f8f1145c7e739a6ffd8806a6d26d60f0443897<br \/>\ndangling blob f1f905a5eb35724622249f25f6d9ef7c646e4283<br \/>\ndangling blob 221417781e017cf02f90b872aea80f30ed41787c<br \/>\ndangling blob c1356b24fb2a4ea453dba87ed4058e7a48e97dce<br \/>\ndangling blob cb6fe3d5321b7b152a8781541bbc6132c59b9c94<br \/>\ndangling blob 3ce2e76cd54f0c8265ec6167f78d5dfe71c2242d<br \/>\ndangling blob daf073729960c40a44c5291c745092445bb2c3b0<\/p>\n<p>[\/shell]<\/p>\n<p>2.git prune<br \/>\nWith git fsck, we identified some of dangling commits and blobs,  now to remove them we use git prune.<br \/>\nNow After running git prune, If I run git fsck again, my git would be cleaner than before and healthy.<\/p>\n<p>[shell]<br \/>\ngit fsck<br \/>\ndangling commit 177864469ea87564ade9101106d5aa85cceb0d29<br \/>\ndangling commit 848665007bc412910b68dc3e528e74c23ce1f165<br \/>\n[\/shell]<br \/>\nBut it still has some dangling commits.This is where git&#8217;s garbage collection comes in play.<br \/>\n<\/br><\/p>\n<p>3.git gc (Garbage Collection)<br \/>\nThis command will gathers up all the loose objects and places them in packfiles. And  removes objects that aren\u2019t reachable from any commit. This command will save some space and speed up many of git commands.<br \/>\nExample<br \/>\n[shell]<br \/>\ngit gc<br \/>\nCounting objects: 121775, done.<br \/>\nDelta compression using up to 4 threads.<br \/>\nCompressing objects: 100% (18239\/18239), done.<br \/>\nWriting objects: 100% (121775\/121775), done.<br \/>\nTotal 121775 (delta 76189), reused 120913 (delta 75659)<br \/>\nRemoving duplicate objects: 100% (256\/256), done.<br \/>\n[\/shell]<\/p>\n<p>Output of this commands tells several things  to us , that is compressed 18239 objects for us out of total 121775 objects. And it also removed 256 duplicate objects. This way my git stayed healthy.<\/p>\n<div>_________________________________<\/div>\n<div>Hitesh Bhatia<br \/>\nMail,LinkedIn,<a href=\"http:\/\/www.facebook.com\/home.php?#%21\/profile.php?id=100000114437286\" target=\"_blank\">Facebook<\/a>,<a href=\"http:\/\/twitter.com\/d1_ricky\" target=\"_blank\">Twitter<\/a><br \/>\n_________________________________<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Since we use git numerous times a day over and over, hence needs maintenance. There are few commands that will help you to keep our git healthy. If you feel that you git has somewhat slowed down, these would do the trick for you. Since ours is a pretty big project . I run it [&hellip;]<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":2},"categories":[7],"tags":[737,740,739,375,736,738],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4908"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=4908"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4908\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=4908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=4908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=4908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}