Skip to content

Instantly share code, notes, and snippets.

@alexanderjsingleton
Last active October 8, 2015 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderjsingleton/766048b8d13f76ccdb80 to your computer and use it in GitHub Desktop.
Save alexanderjsingleton/766048b8d13f76ccdb80 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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