Skip to content

Instantly share code, notes, and snippets.

@heloa-net
Created January 4, 2017 01:58
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heloa-net/0814112c65c137fc2fb9eef29bd15b6e to your computer and use it in GitHub Desktop.
Save heloa-net/0814112c65c137fc2fb9eef29bd15b6e to your computer and use it in GitHub Desktop.
Hiding API keys on GitHub without breaking your project

Backup the API key beforehand in case you have trouble reverting the file.

Let's say the file with a key you want to hide is <filename> Open it and change the API key with a placeholder, like <api-key> Save and add the file to git and commit git commit -m 'Masking API key'

Then revert the file, undoing recent changes so your key is back where it should be and save it. Use git update-index --assume-unchanged <filename> with the file where the key is so that git no longer tracks changes to this file, so you won't be bothered to push the real key to the repository.

If you need to make changes to this file and have git track them, use: git update-index --no-assume-unchanged <filename>

@lmeijdam
Copy link

Thanks! Was searching for this!

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