# How to Ignore Vendor Directories in PHP, Go, and Other Dependency Folders

> Easily ignore vendor directories in PHP, Go, and other dependency folders. Learn how to add vendor lines to your .gitignore file and streamline your Git workflow for cleaner repositories.

- Repository: [GitHub/gitignore](https://github.com/github/gitignore)
- Tags: how-to-guide
- Published: 2026-02-24

---

**Add `/vendor/` to your `.gitignore` file for PHP projects, or uncomment the `vendor/` line in Go projects, to prevent Git from tracking third-party dependency folders.**

The official `github/gitignore` repository provides battle-tested templates for excluding dependency directories across major programming languages. Learning how to properly **ignore vendor directories** keeps your repositories lightweight and prevents accidental commits of external code that should be installed via package managers.

## Ignoring Vendor Directories in PHP Projects

PHP ecosystems universally use the `vendor/` directory for Composer-managed dependencies. The official gitignore templates anchor this pattern to the repository root to ensure precise matching.

### Composer-Based Projects

In `Composer.gitignore`, the pattern appears at line 2:

```gitignore
/vendor/

```

This single line tells Git to ignore the entire Composer dependency folder at the root level. For library projects, this is the minimal configuration required.

### Laravel Applications

The `Laravel.gitignore` template places this rule at the very top (line 1), reflecting its importance in full-stack PHP frameworks:

```gitignore
/vendor/

```

This ensures that framework dependencies installed via Composer never enter version control.

### Symfony Projects

In `Symfony.gitignore`, the vendor ignore pattern appears at line 32 alongside other framework-specific exclusions:

```gitignore
/vendor/

```

All three templates use the leading slash (`/`) to anchor the pattern to the repository root, preventing accidental matches of directories named `vendor` in other parts of your codebase.

## Ignoring Vendor Directories in Go Projects

Go modules handle vendoring differently. The `Go.gitignore` template includes a commented-out entry at line 20 that you must manually enable:

```gitignore

# vendor/

```

To ignore vendored Go modules, remove the leading `#`:

```gitignore
vendor/

```

Unlike the PHP templates, the Go pattern typically omits the leading slash when enabled, allowing Git to ignore `vendor` directories at any nesting level within your project.

## Other Dependency Folders to Ignore

The same principle applies across language ecosystems. When working with mixed-language repositories or other technologies, reference these standard patterns:

- **Node.js/npm**: `node_modules/` (present in `Node.gitignore`)
- **Ruby/Bundler**: `vendor/` or `vendor/bundle/`
- **Python**: `site-packages/` or `venv/`
- **Bower**: `bower_components/`

For polyglot projects, combine patterns in a single `.gitignore`:

```gitignore

# PHP (Composer)

/vendor/

# Go (vendored modules)

vendor/

# Node.js

node_modules/

```

## Understanding Anchored vs. Unanchored Patterns

Git evaluates ignore rules top-down. A leading slash anchors the pattern to the repository root:

- `/vendor/` — Ignores only the `vendor` directory at the root level
- `vendor/` — Ignores any directory named `vendor` at any depth

The official PHP templates prefer `/vendor/` to avoid accidentally ignoring legitimate directories named "vendor" deep within your source tree. Go projects often use the unanchored version because vendored dependencies might exist in sub-packages.

## Summary

- **Add `/vendor/`** to ignore Composer dependencies in PHP projects, as implemented in `Laravel.gitignore`, `Composer.gitignore`, and `Symfony.gitignore`
- **Uncomment the line** in `Go.gitignore` (line 20) to enable vendor ignoring for Go modules
- **Use leading slashes** (`/pattern/`) to anchor ignores to the repository root and prevent unintended matches
- **Combine patterns** when working with multiple languages in the same repository
- **Never commit dependency folders** that can be reconstructed from lock files (`composer.lock`, `go.mod`, [`package-lock.json`](https://github.com/github/gitignore/blob/main/package-lock.json))

## Frequently Asked Questions

### What is the difference between `/vendor/` and `vendor/` in gitignore?

The leading slash anchors the pattern to the repository root. `/vendor/` ignores only the top-level vendor directory, while `vendor/` ignores any directory named vendor at any nesting level. The PHP templates in the github/gitignore repository use `/vendor/` to avoid accidentally matching unrelated vendor directories in your application code.

### Why is the vendor line commented out in Go.gitignore?

The Go toolchain handles vendoring specially. The `Go.gitignore` template at line 20 includes `# vendor/` as a commented suggestion because vendored dependencies are sometimes intentionally committed to ensure reproducible builds in older Go versions or specific deployment scenarios. Uncomment the line only if you want Git to ignore your local `vendor/` directory.

### Should I commit the vendor directory in PHP projects?

No. The `vendor/` directory in PHP projects contains third-party code managed by Composer. You should ignore vendor directories by adding `/vendor/` to your `.gitignore` and commit only the [`composer.json`](https://github.com/github/gitignore/blob/main/composer.json) and `composer.lock` files. This keeps your repository small and allows team members to install the exact same dependency versions via `composer install`.

### How do I handle vendor directories in a multi-language monorepo?

Create a root `.gitignore` file that combines language-specific patterns. For example, include `/vendor/` for PHP components at the root, `vendor/` for Go sub-modules, and `**/node_modules/` for JavaScript packages. Reference the official templates in `github/gitignore` for each language to ensure you're using the community-standard patterns.