Skip to content

Instantly share code, notes, and snippets.

@trcook
Last active August 29, 2015 14:16
Show Gist options
  • Save trcook/dcbe3b122a8daeb2f0db to your computer and use it in GitHub Desktop.
Save trcook/dcbe3b122a8daeb2f0db to your computer and use it in GitHub Desktop.
set file to be included in repo but for changes to be ignored. This is useful for making a configuration file that has sensitive data in it.

Put file in repo and ignore changes

This is good for security so you can make a template file for security keys or whatever without commiting your own keys by accident.

setup the file

First, set the file up how you want it to look in the repo:

touch <file>
subl3 <file>

enter the proper setup for the file

then commit the file to the repo:

git add <file>
git commit -m "added <file>"

stop tracking but keep file

use update-index to stop tracking the file:

git update-index --assume-unchanged <file>

change as needed

Now you can put sensitive data in the file Changes will not be reflected in the index

Revert for changes

If you need to make changes, copy the file with sensitive info. Put this somewhere else. you are about to overwrite it with the sanitized version tracked in the git repo -- you'll want to copy-paste its contents back in when you're done.

Checkout the HEAD file from the repo and set tracking back on :

git checkout <file>
git update-index --no-assume-unchanged <file>

Change the file accordingly, and commit changes. Then turn tracking back off with

git update-index --assume-unchanged <file>

and copy the file with sensitive data back in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment