Categories:

Cleanup .git object files

If you ever had a massive object files under directory /myproject/.git/objects then you come to right place, this tutorial will tech you how to clean up them

Method 1

Go into your current project root directory, exectue these code below

git reflog expire --expire=now --all
git repack -ad  # Remove dangling objects from packfiles
git prune       # Remove dangling loose objects

// OR

rm -f .git/objects/*/tmp_*


Method 2

If you clone another ppl repo with a huge previous commit message, and you want to start with a clean repo, there are 2 simple ways to do this.

First method

git clone --no-hardlinks blah.git

Second method

git checkout --orphan tmp
git add -A
git commit -m "clean project"
git branch -D master
git branch -m master
git push -f origin master

// Gitlab error 
remote: GitLab: You are not allowed to force push code to a protected branch on this project.

// Solution
Unprotect this repo: Settings -> Repository -> Protected branch -> unprotect

References:

  1. https://stackoverflow.com/questions/5277467/how-can-i-clean-my-git-folder-cleaned-up-my-project-directory-but-git-is-sti
  2. https://blog.csdn.net/dounine/article/details/77840416

Photo by Kent Pilcher on Unsplash