Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce .git folder size

Tags:

git

github

There is such question albeit old one, but it didn't seem to help. I have repo. In the repo I have a gif file which is roughly 6MB. It happenned so that I pushed different versions of this GIF and apparently all of them are stored in .git folder, which made the size of git folder around 40MB.

From the project folder I tried running as suggested in linked question:

   git repack -a -d --depth=250 --window=250

But it didn't affect the size of .git folder (do I have to push to see the size reduced?). Is there something I can do to reduce .git folder size?

Also trying git gc didn't seem to reduce .git folder size.

like image 290
Giorgi Moniava Avatar asked Dec 03 '18 15:12

Giorgi Moniava


1 Answers

A hacky solution:

git push # ensure that you push all your last commits from all branches, and
         # take care about your stashes as well because we are going to delete
         # everything.
cd ..
rm -rf online-shop
git clone --depth 1 [email protected]:giorgi-m/online-shop.git

This last line will clone the repository with only a one commit history.

Hence your .git folder will be much lighter. However, you will not have the whole history on your computer and this may not be what you are looking for.

For other users that would like to clone your application, you can tell them in the README file that they can fasten download by using the next command:

git clone --depth 1 [email protected]:giorgi-m/online-shop.git

Another solution, which is rewriting history, would be to remove all your remote history. You can see more about it in this answer:

Deleting the .git folder may cause problems in your git repository. If you want to delete all your commit history but keep the code in its current state, it is very safe to do it as in the following:

Checkout

git checkout --orphan latest_branch

Add all the files

git add -A

Commit the changes

git commit -am "commit message"

Delete the branch

git branch -D master

Rename the current branch to master

git branch -m master

Finally, force update your repository

git push -f origin master

PS: this will not keep your old commit history around

like image 74
Ulysse BN Avatar answered Oct 21 '22 09:10

Ulysse BN