Ignore every bin directory in a Git repository

Use directory patterns in .gitignore, remove generated files from the index, and keep an explicit exception for a bin directory you need to track.

Best practices
Illustration of application modules working together

Add bin/ to the repository's root .gitignore to ignore directories named bin at any depth. This affects untracked files; adding the rule does not stop Git from tracking files already in its index.

Choose the matching scope

# Ignore generated bin directories at every level.
bin/

In a root .gitignore, bin/ matches both bin/ and tools/bin/. /bin/ matches only the root directory. **/bin/ explicitly expresses the same recursive scope as bin/. A .gitignore inside a subdirectory applies relative to that directory instead.

The trailing slash matters: bin/ matches directories, whereas bin also matches a regular file with that name.

Stop tracking generated files

First confirm that the tracked files are rebuildable output. Remove each intended directory from the index:

git rm -r --cached -- bin/
git rm -r --cached -- tools/bin/
git add .gitignore
git diff --cached
git commit -m "Stop tracking generated bin directories"

--cached keeps your working copies. The commit records their deletion from the repository, so teammates who update may lose their previously tracked copies. Preserve anything that cannot be regenerated before sharing that change.

Check the rule

git check-ignore -v tools/bin/app.exe
git status --ignored

The first command identifies the matching file, line, and pattern. If a tracked file still appears in git status, remove it from the index deliberately; ignore rules do not hide changes to tracked content. To inspect the pattern independently of tracking status, use git check-ignore -v --no-index tools/bin/app.exe.

Keep one exception

bin/
# Keep this particular directory eligible for tracking.
!scripts/bin/

Put the exception after the general rule. Comments belong on their own lines: a trailing # comment on a pattern line would become part of the pattern. Any excluded parent directory must also be re-included before Git can discover files below it. Other matching rules can still exclude individual files; check the final result before adding them.

Commit .gitignore to share the policy with the team. Use .git/info/exclude for exclusions that should remain local to your checkout.

See the gitignore pattern reference.

Related reading

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting