Skip to content

.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

# 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:

cp /opt/templates/gitignore-r .gitignore

From R, usethis::use_git_ignore() adds entries to .gitignore as a set union, so rerunning it does not duplicate existing lines:5

usethis::use_git_ignore(c(".Renviron", "*.rds", "output/"))

Already committed something

Remove from Git but keep the local file:6

git rm --cached .Renviron
git rm -r --cached .Rproj.user/
git commit -m "Stop tracking local files"

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

git status --ignored
git check-ignore -v path/to/file

A global ignore file

Personal editor and OS files belong in a global ignore, not in every project:1

git config --global core.excludesfile ~/.gitignore_global
# ~/.gitignore_global
.DS_Store
.Rhistory
.RData
*.swp