This has to be in an Event callback called GIT_ENABLED so it won't fire when there's no Git repository. This event is also called when you switch between projects so you don't need to worry about that.