Is it possible to ignore specific files in git only for certain remotes? e.g., I'm storing AWS S3 credentials (s3.yml
) in a file for an app hosted on Heroku, thus I need to check s3.yml
into my repo for the deploy to work. However, I'd like to publish the source to GitHub as well, so I would be wise to keep s3.yml
out of the repo. I would imagine it working something like
#.gitignore
github:config/s3.yml
but haven't been able to find anything in the git docs. Is this possible? Or do I need to maintain two separate repos?
Thanks!
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a .gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
If you don't want Git to track certain files in your repository, there is no Git command you can use. (Although you can stop tracking a file with the git rm command, such as git rm --cached .) Instead, you need to use a . gitignore file, a text file that tells Git which files not to track.
gitignore. To commit these files, you'll first need to derive them from the Git repository. The . gitignore will prevent files that Git does not track from being added to the set of files that the version control system is tracking.
You just need to add the file to . git/info/exclude in the same way you would add it to . gitignore .
That file is always going to live in the repo if you publish it as is. Even if you created a branch and git-rm'd the file, people would always be able to check out the version that still had the file. I don't see any way of using a single repository while keeping a single file inaccessible on a remote.
The core problem is that, as a distributed SCM, each repository has a full revision history. Since the changelists are cryptographically signed based on their content, it's not possible to erase a file without changing the hash of each changelist all the way back to when the file was added. This is something git can do, but at that point you have two separate repositories that won't be able to directly/easily push/pull.
Heroku has config-vars for this sort of thing. Their opinion seems to be that the s3 information shouldn't be checking into Git. Check out this link for more information about how they're expecting this sort of thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With