How to change .gitignore before deploy to Heroku?

Hi, I have this Travis config:
language: python
python: "3.7.5"
cache: pip
install: pip install -r requirements.txt
script: pytest -q test/
- "sed -i '/' .gitignore > .gitignore"
- "sed -i '/credentials.json/d' .gitignore > .gitignore"
- "git add .gitignore"
- "git commit -m 'Update .gitignore.'"
provider: heroku
secure: key_is_here
app: dadyarri-ralph-2

I don’t want to see and credentials.json in Github repo, but i need them in Heroku. How can I do that, and why current config isn’t working (Travis don’t print any warnings but code at Heroku fails: ModuleNotFoundError: No module named 'config')

Try before_deploy.

It is in my config. But i dunno what i should put into it. This version isn’t working

I see. I didn’t catch it on my first reading. I note here that the configuration you’ve shown is not properly formatted and may contain some more errors.


  1. The default deployment strategy to Heroku is API. If you are relying on .gitignore to work some magic, this may not be the right choice.

  2. Do you know if these sed commands you have in before_deploy work? My understanding is that, with > .gitignore, bash would first clean out the content of the existing .gitignore file before invoking sed. I think the result would be such that .gitignore is empty.

    $ cat .gitignore
    $ sed -i '/A/d' .gitignore > .gitignore
    $ cat .gitignore

    sed's -i flag should automatically take care of this, so you should just call sed -i … without I/O redirection.

In repo it formatted properly.

  1. It should use api, i dont change it to git, dont know, why it’s honor .gitignore
    2.I’ve fixed it after this question ( removed redirect output). Dont working too. More, it’s now outputs fatal: pathspec '' did not match any files

Upd.: what if this just because and credentials.json wasn’t on github? Then, how to trigger travis with local repo?