Is there a way to reduce the size of the git folder?
Run:
git remote prune origin
Deletes all stale tracking branches which have already been removed at origin
but are still locally available in remotes/origin
.
git gc --auto
'G arbage C ollection' - runs housekeeping tasks (compresses revisions, removes loose/inaccessible objects). The --auto
flag first determines whether any work is required, and exits without doing anything if not.
One scenario where your git repo will get seriously bigger with each commit is one where you are committing binary files that you generate regularly. Their storage won't be as efficient than text file.
Another is one where you have a huge number of files within one repo (which is a limit of git) instead of several subrepos (managed as submodules).
In this article on git space, AlBlue mentions:
Note that Git (and Hg, and other DVCSs) do suffer from a problem where (large) binaries are checked in, then deleted, as they'll still show up in the repository and take up space, even if they're not current.
If you have large binaries stored in your git repo, you may consider:
- managing those binaries in an external repository.
- manage your .git repo size
- try and remove those binaries from your history with
git filter-branch
(warning: this will rewrite the history, which is bad if you have already pushed your repo and if other have pulled from it)
As I mentioned in "What are the file limits in Git (number and size)?", the more recent (2015, 5 years after this answer) Git LFS from GitHub is a way to manage those large files (by storing them outside the Git repository).
I'm not sure what you want. First of all, of course each time you commit/push the directory is going to get a little larger, since it has to store each of those additional commits.
However, probably you want git gc
which will "cleanup unnecessary files and optimize the local repository" (manual page).
Another possibly relevant command is git clean
which will delete untracked files from your tree (manual page).
yes yes, git gc
is the solution, naturally,
and locally - you can just delete the local repository and clone it again,
but there is something more important here...
the seconds you wait for that huge git & externals to process are collected to long minutes in which are collected to hours of inefficient time spent,
Create a new (entirely, not just a branch) repository from scratch, including the only recent version of files, naturally you'll loose all the history,
but when in code-world it is not time to get sentimental, there is no point dragging along the entire 5 years of code every commit or diff, you can still store the old git & externals somewhere, if you get nostalgic :]
but, at some point you really have to move along :]
your team will thank you!