.gitignore for Workbench Projects¶
Users regularly commit things that should never be in Git: credentials in .Renviron, gigabytes of data, entire renv libraries. A standard .gitignore prevents most of it.1
Recommended template¶
# R and IDE state ----
.Rproj.user/
.Rhistory
.RData
.Ruserdata
.positron/
.quarto/
# Credentials and secrets ----
.Renviron
.env
*.pem
*.key
credentials.json
secrets/
# Connect deployment records (local to each user) ----
rsconnect/
rsconnect-python/
# Package development ----
*.tar.gz
*.Rcheck/
# Logs ----
*.log
# Data (adjust per project) ----
data-raw/*.csv
*.rds
*.rda
*.parquet
*.xlsx
*.sas7bdat
*.xpt
# Rendered output ----
*_files/
*_cache/
_site/
_book/
output/
# Python ----
__pycache__/
*.py[cod]
.venv/
venv/
.ipynb_checkpoints/
# OS and editor files ----
.DS_Store
Thumbs.db
*~
*.swp
.idea/
rsconnect/ and rsconnect-python/ are the local deployment record directories created by the R and Python publishing clients. Both are excluded from deployment bundles by default, but they still belong in .gitignore so they are never committed.4
What not to ignore¶
Some popular templates ignore files that you need:
| File | Keep it because |
|---|---|
manifest.json |
Git backed deployment on Connect reads it from the repository. Ignoring it breaks Git publishing. Regenerate with rsconnect::writeManifest()2 |
renv.lock |
It is the record of package versions |
renv/activate.R, renv/settings.json, .Rprofile |
Needed to restore the project. renv writes its own .gitignore for the library, so you do not need rules for renv/library/3 |
requirements.txt, pyproject.toml, uv.lock |
Python equivalents of the lockfile |
*.Rproj |
Project settings shared by the team (ignore it only if your team agrees) |
.dockerignore |
Belongs in the repository with the Dockerfile |
In regulated projects, data and output files may need to be retained, just not in Git. Agree with QA where they live.
Create one quickly¶
Keep the template above in a shared location (for example /opt/templates/gitignore-r) and copy it into new projects:
From R, usethis::use_git_ignore() adds entries to .gitignore as a set union, so rerunning it does not duplicate existing lines:5
Already committed something¶
Remove from Git but keep the local file:6
If a secret was committed and pushed, removing it in a new commit is not enough: it is still in history. Rotate the secret immediately, then clean history with git filter-repo, Git's own recommended replacement for git filter-branch, if required.7
Check what is ignored¶
git status --ignored shows ignored paths in the working tree; git check-ignore -v shows which pattern, in which file, is responsible for ignoring a given path.89
A global ignore file¶
Personal editor and OS files belong in a global ignore, not in every project:1