Hiding Git in Apache

Let’s start with something light in this first post. I am using git for version control in one of my web applications, but the files in .git and .gitignore were accessible. I went searching for a solution and came accross this.

The solution is simple, just append the following line in the ROOT of your webserver

RedirectMatch 404 /\.git

Then reload apache and viola! All git related files in any subdirectories are now hidden from prying eyes.