Development Workflow

Use Git Ignore Rules for PHP Project Artifacts

Keep generated dependencies, local secrets, logs and runtime files out of a PHP project Git repository.

A clean PHP repository contains the source and project metadata needed to reproduce the application, not every file generated on a developer's machine. A thoughtful .gitignore prevents accidental commits of secrets, caches and bulky runtime artifacts.

Identify generated and private files

Common candidates include .env files, IDE workspace settings, operating-system metadata, logs, cache directories, session files, temporary uploads and local database dumps. The exact list depends on the application. Do not ignore source assets or migration files simply because they are generated during one developer's workflow.

Decide how to handle vendor

For Composer applications, vendor/ is normally generated from composer.lock and is not committed. The lock file should be committed for applications. A library package may follow a different distribution workflow, so document the choice.

Use a safe baseline

/vendor/
/.env
/.env.*
!/.env.example
/var/cache/
/var/log/
/storage/private/
*.log
.phpunit.cache/
/.idea/workspace.xml
/.vscode/

This is a starting point, not a universal policy. Confirm each path against the project's deployment and build process. Some teams intentionally commit selected VS Code settings or IDE metadata.

Check what Git is tracking

Use git status --ignored to inspect ignored files and git check-ignore -v path to identify the rule responsible. .gitignore does not remove a file that is already tracked; use git rm --cached when intentionally untracking a generated file.

Respond to accidental exposure

If a credential was committed, revoke or rotate it immediately. Removing it from the latest commit does not make the old value safe because it may remain in repository history and clones.

Further reading

Share this page Help other developers discover this resource.