To keep generated files separate from source code on a Mac, create a dedicated output folder inside the repository, then add that folder to the repository’s .gitignore file. Finder helps you create and inspect the folders; Git’s ignore rules keep generated output out of future commits. This works for files Git does not already track, so check the repository status before relying on it.
Create an output folder in Finder
Open the repository folder in Finder and create a folder for generated output, such as build or dist, using File > New Folder or Shift-Command-N. Keep source files in their existing locations and configure your build tool to write its output to that folder. The folder name must match the tool’s actual output path; creating a folder alone does not redirect a build. Apple documents Finder’s folder creation steps in its guide to organizing files in Finder.
If you are not sure which files are generated, check your build tool’s configuration or project documentation before moving or excluding anything. Some generated files are required by the project or intentionally checked in. Keep those files under version control if the project needs them.
Add the generated folder to .gitignore
In the repository root, create or open a file named .gitignore in a text editor. Finder can create folders and move files, but it does not provide Git ignore controls; Git reads ignore patterns from .gitignore and related configuration. Add a rule for the output directory, using the actual path relative to the .gitignore file. For example:
/build/
A leading slash anchors this pattern at the repository root, and the trailing slash makes it match a directory. If your generated output is nested, use its path instead, such as /app/generated/. Git’s gitignore documentation explains pattern matching and notes that project-wide rules belong in .gitignore so they can be shared with other clones.
For a local generated folder that should not affect other people working on the repository, add its rule to .git/info/exclude instead. Git documents this as a repository-specific alternative to .gitignore. Use a committed .gitignore rule when the output is generated for everyone on the project and should be excluded for all contributors.
Confirm the rule and handle files already tracked
Open Terminal and change to the repository directory. Check the status, then ask Git which rule applies to a generated path:
git status --short
git check-ignore -v build/example-file
Replace build/example-file with a path that exists under your output folder. The -v option reports the matching ignore rule and the file containing it. If Git reports no match, confirm the path and pattern: paths in .gitignore are interpreted relative to the file’s location, and a rule may be overridden by another matching rule. Git’s check-ignore reference describes how to inspect ignore matches.
An ignore rule does not stop tracking files already committed or staged in Git. Git explicitly says tracked files are unaffected by ignore rules. To remove a previously tracked generated file from the index while leaving the local copy in place, use git rm --cached with the precise path, then review the change before committing. For example:
git rm --cached build/example-file
git status --short
This removes only the named file from Git’s index; it does not automatically untrack every file in a directory. Review the status output, especially if you intend to untrack a whole output tree, before committing the change. The GitHub guide to ignoring files also explains the distinction between local exclusions and shared .gitignore rules.
Use Finder to inspect names, not to enforce Git rules
Finder can make file types easier to inspect: choose Finder > Settings > Advanced and enable Show all filename extensions. This can help distinguish a source file from a generated file when their names are similar. Apple notes that extensions may otherwise be hidden and advises against changing a filename extension merely to change a file’s format. See Apple’s instructions for showing or hiding filename extensions.
The reliable division is therefore: Finder provides a visible folder for generated output, the build tool writes there, and Git ignore rules exclude eligible untracked files from version control. Check the actual output path and Git status whenever the project’s build configuration changes.
Sources
Ignoring files — GitHub Docs