2

so i've installed git into my computer long time ago but recently noticed i'm out of space and theres folder called .git which takes almost 18GB Storage. when exploring the folder i found some meaningless weird files don't know where that came from. I'm thinking to delete it but a bit worry if its important for my mac or some file system. if any one has this file please let me know about its purpose so i can decide what to do with it. enter image description here

1615903
  • 32,635
  • 12
  • 70
  • 99
OT AMD
  • 183
  • 5
  • 19

2 Answers2

0

It (the .git/ directory) is the directory used by git for all its data and meta-data.

If you remove it, you won't be able to use git anymore on that particular source tree.

You should try first to run git gc.

I'm surprised you have such a huge .git. Perhaps you have unwillingly git add-ed some executable or some other rather big binary file which often changes. You'll better use git only for source code. You might consider having some .gitignore file and at least git rm large binary files.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • 2
    However, it's (in my eyes) strange, that you have created a git repository in your home folder. Was this on purpose? or have you maybe created it accidentally on that level? – dunni Nov 05 '17 at 12:45
  • im sure i did not make that huge repository but was shocked when i notice it at first – OT AMD Nov 05 '17 at 14:23
0

Warning: git gc is now (2021) replaced with git maintenance (man page), and running it on MacOs can fail (which means your huge .git folder would not be cleaned up)

With Git 2.34 (Q4 2021), "git maintenance"(man) scheduler fix for macOS.

See commit a16eb6b (24 Aug 2021) by Derrick Stolee (derrickstolee).
See commit bb01122 (24 Aug 2021) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit 4293c05, 08 Sep 2021)

maintenance: skip bootout/bootstrap when plist is registered

Signed-off-by: Derrick Stolee
Signed-off-by: Johannes Schindelin

On macOS, we use launchctl to manage the background maintenance schedule.
This uses a set of .plist files to describe the schedule, but these files are also registered with 'launchctl bootstrap'.

If multiple 'git maintenance start'(man) commands run concurrently, then they can collide replacing these schedule files and registering them with launchctl.

To avoid extra launchctl commands, do a check for the .plist files on disk and check if they are registered using 'launchctl list <name>'.
This command will return with exit code 0 if it exists, or exit code 113 if it does not.

We can test this behavior using the GIT_TEST_MAINT_SCHEDULER environment variable.

GIT_TEST_MAINT_SCHEDULER=launchctl:./print-args git maintenance start
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250