Using Git Hooks to automate server-side stuff

I have seen that some people were having issues like git clogging up their project’s disk space and they had to run git gc in the terminal to fix this. Well I have also been having this issue with one my projects (Constant file edits and changes) and had to run git gc on every push to fix it, and thats quite annoying.

I managed to find a solution to this, so I thought to share it as it might help others.

The final solution was to use a githook to run the git gc command.
This can also be used to automatically refresh the editor using the refresh command.

The hook that we want is post-receive.

git gc

You can create this file by running printf '#!/bin/sh\ngit gc\nrefresh' > .git/hooks/post-receive in the glitch terminal, after this you need to give it executable permissions by running chmod +x .git/hooks/post-receive and that’s it.

You can push to the git repository of your project and keep the editor open to see this in action!