How to protect .git folder using htaccess

GIT is popular version control software, this work like a time machine. You can easily get older versions of code. Each changes are stored as commit, so it work like a time machine for source code.

If you put your .git folder in a publically accessable folder, others will be able to access your source code. It is better put this folder outside of DocumentRoot folder.

If your .git folder is on public folder, then use following .htaccess code to block access to it.

RedirectMatch 404 /\.git

Method 2

Create an .htaccess file inside .git folder with content

deny from all

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *