liveBook · Manning

.gitignore

As explained in Build Python Web Apps with Streamlit

A .gitignore file specifies files and directories that Git should exclude from version-control operations such as commits.

A .gitignore file tells Git which files or directories to leave out of commits. Keep sensitive configuration such as .streamlit/secrets.toml locally while sharing the application code. section 5.4.2

Use .gitignore as part of a safe deployment workflow:

  • Create an empty .gitignore file in the repository root if one does not exist. section 5.4.2
  • Add .streamlit/ to exclude secrets.toml and other files in that directory. section 5.4.2
  • If Git already tracks the directory, remove it from the index with git rm -r --cached .streamlit/. section 5.4.2
  • For Elastic Beanstalk deployments, also ignore .ebextensions/ and .elasticbeanstalk/ when they contain deployment configuration or generated settings. section 12.3.5

Protecting Streamlit secrets

A repository can contain .streamlit/secrets.toml locally while its root .gitignore contains .streamlit/. Running git add or git commit then leaves the secrets directory out of the commit. section 5.4.2

Root of your Git repo
├── .streamlit (folder)
│   └── secrets.toml
├── .gitignore
├── requirements.txt
├── jokes.py
├── task.py
└── todo_list.py

Use the repository layout to see where .gitignore belongs relative to .streamlit/secrets.toml and the application files. section 5.4.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains file placement, ignore entries, and removing already tracked files, but does not detail pattern syntax.
Examples
Uses .streamlit/secrets.toml, .ebextensions/, .elasticbeanstalk/, and git rm -r --cached .streamlit/ as concrete examples.
What it assumes
Assumes a Git repository and introduces the repository-root location and commit-protection purpose from the beginning.
What you can do after
Configure Git to omit sensitive local files and remove previously tracked secrets from its index.
How it connects
Connects Git with secrets.toml, Streamlit Community Cloud, Elastic Beanstalk, Docker, and version control.

Also explained in

Compare how 2 books explain .gitignore →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.