[git][windows] Preventing local file bloat

I’m using GitHub Desktop and git.exe for my repo and am running into an issue.

Over time the local repos folder bloats out to over 500MB for a remote repo that is under 11MB.

I have a PowerShell script that runs the following commands:

clean -f
checkout --orphan TEMP_BRANCH
add -A
commit -am "Initial Commit"
branch -D master
branch -m master
push -f origin master

I’m trying to get it to:

  1. retain the latest commit only
  2. delete all old history and old files
  3. clean the .git folder

for both remote and local.

Any ideas?

checkout --orphan TEMP\_BRANCH HEAD~1

to get only the last commit?

No, that’s not right I think.

I know that “git clone” has a --depth option to get a limited history. 

1 Like

It sounds like you’re using git for something that it wasn’t designed for. I suspect that you have a lot of binary files in the repository, files such as audio, image, or video files. And then on top of that, you’re intentionally not using any of the version control features of git, using it only as a remote file storage mechanism.

Unfortunately, it’s not possible to tell git to work in such a way. It’s going to assume that you’re trying to use it as a version control system and keep extra data around in case you decide to refer back to it. You could look into the git gc command to see if it could help, but I would still recommend using a different tool that is better designed for what you’re trying to do.

I hope that helps!

1 Like

Potentially useful article about using git-sizer to determine how your repository is “too big”.

Also, is 500M “size” or “allocated size”? I have a 5M repo which occupies 75M of disk space on one device - each of many 1K files occupies 128K of allocated disk space.

1 Like

Thanks everyone for the replies :smiley:

To prevent bloat I’ve decided to just delete the local repo folder and clone down the repo after every 20 commits.