Reputation: 28654
There is such a question, albeit an old one, but it didn't seem to help.
I have a repository. In the repository, I have a GIF file which is roughly 6 MB. It happened so that I pushed different versions of this GIF and apparently all of them were stored in the .git folder, which made the size of the Git folder around 40 MB.
From the project folder, I tried running as suggested in the linked question:
git repack -a -d --depth=250 --window=250
But it didn't affect the size of the .git folder (do I have to push to see the size reduced?). Is there something I can do to reduce the .git folder size?
Also trying git gc
didn't seem to reduce the .git folder size.
Upvotes: 6
Views: 8968
Reputation: 11376
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
Upvotes: 12