Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
For the derpy, albeit accidental, push to origin including your secrets.yml file...
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch config/secrets.yml' --prune-empty --tag-name-filter cat -- --all
@alexanderjsingleton

This comment has been minimized.

Copy link
Owner Author

commented Sep 27, 2015

The above Git command was necessitated after utilizing the Figaro gem to create environment variables for secure authentication. For additional questions or concerns, consult the Git Prune documentation.

If using Rails 4.1 or newer, secret keys should be created in config/secrets.yml, and set differently based on the environment. In this case, generate a random token and set it as ENV['SECRET_KEY_BASE’] to use at a staging-area, like Heroku. Run rake secret from the command line to generate a token, and heroku config:set SECRET_KEY_BASE=thegeneratedtoken to set that token to that ENV variable on production.

Add SECRET_KEY_BASE to your application.yml, then use Figaro to sync the tokens on Production and Development. Then set the Development key to equal the same ENV-stored token as the Production key in secrets.yml. This creates individual, unique tokens for development and production environment variables.


Presumably, the aforementioned effected, so include the application.yml and secrets.yml files in .gitignore. In my experience, an immediate commit, merge, and push to origin could include these files, which obviously defeats the purpose of authentication-so commit, merge to master, _but before pushing to origin_, consider the following, found on StackOverflow:

To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename

To untrack every file that is now in your .gitignore:

First commit any outstanding code changes, and then, run this command:

git rm -r --cached .

This removes any changed files from the index(staging area), then just run:

git add .

Commit it:

git commit -m ".gitignore is now working"

To undo git rm --cached filename, use git add filename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.