Committing files once then ignoring them with Git

I’ve been working on ReviewMy.MP lately (RMMP). RMMP is a web application built in Laravel v4.1 that will allow Australians to review their members of parliament based on a few criteria so users can find out what really represents them and their views.

The project has been open sourced and you can check out the code on GitHub. As part of the open sourcing I wanted to make sure users can copy the project and get started straight away but I can’t allow them to view things like the application key (used for hashing passwords and other things) or database tables.

Laravel stores all this information in the app/config directory.

I initially tried to use .gitignore but because the files were already in the project Git would track their changes. I then tried to use:

git rm -rf app/config

This meant that it removed my files from Git entirely, which is not what I wanted and I had to pull my last commit from Origin/Master to get my config files back.

I found this GitHub page that discussed –assume-unchanged. It covered exactly what I wanted but it would only work on specific files and not an entire directory thankfully there was a Stack Overflow thread that gave me the answer I needed and now I can change my config files and make sure they’re secure and unavailable for users to find while also giving users some sort of beginner framework for them to work with if they want to implement the project for themselves.

This is the code I used to make git assume there were no changes to my app/config directory:

<code>git ls-files -z &lt;MyFolderToIgnore&gt; | xargs -0 git update-index --assume-unchanged</code>

And this is the code to remove the assumption:

<code>git ls-files -z &lt;MyFolderToIgnore&gt; | xargs -0 git update-index -un-assume-unchanged</code>

About Nick

Melbourne based web developer that loves building front-end systems with anything from vanilla JS to React. Infosec student and active learner. Subscribe to the blog

www ·

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.