Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does git duplicate all my files?

I am trying to implement a new backup system on a website using git. The virtual private server has 20GB space total with 5GB free.

When I run git add . at the /var/www (with my favorite .gitignore parameters) I have a gigantic git folder that fills my hard drive to capacity.

It is not immediately apparent as to why this is happening as I expect the .git directory to contain the bits about the bits (meta information) and not binary duplicates of all my files!

Whats going on here? If my website is 14GB will the .git directory occupy an additional 14 gb?

like image 935
Mikhail Avatar asked Jun 22 '26 03:06

Mikhail


2 Answers

Space Used Equals GIT_DIR + GIT_WORK_TREE

If my website is 14GB will the .git directory occupy an additional 14 gb?

To oversimplify the case enormously, yes. In a non-bare respository, Git stores all tracked file blobs, as well as other repository objects such as trees and commits under GIT_DIR. It also maintains copies in the GIT_WORK_TREE.

The repository uses packfiles and deltification to keep this state of affairs from getting out of hand in the normal use case, but if you have 14GB+ of data in a non-bare respository--especially if a lot of those files are binary assets--then you may very well double-up (or worse) on disk usage.

like image 114
Todd A. Jacobs Avatar answered Jun 23 '26 17:06

Todd A. Jacobs


A git repo contains the entire history of the files. The .git folder will contain all of the bits that are in your working directory, so you can expect it to increase the size. It won't be double due to compression, but it will be significant. And as you change the files, the total size of the repo will increase, even if the size of the working tree doesn't, because the history is stored.

like image 39
Ned Batchelder Avatar answered Jun 23 '26 17:06

Ned Batchelder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!