Git Ignore¶
This guide explains how to use
.gitignoreto prevent Git from tracking specific files or directories. It is intended for technical users and assumes no prior knowledge.
Tags¶
- git
- ignore
- .gitignore
- workflow
- repository
What is .gitignore?¶
.gitignore is a configuration file that tells Git which files or directories to ignore. Ignored files are not tracked, committed, or pushed to remote repositories.
How to Use .gitignore¶
- Create a
.gitignorefile in the root of your repository. - Add patterns or file names for files and directories you want to ignore.
Examples¶
- Ignore all
.logfiles: - Ignore a directory named
installed_binaries:
Multiple .gitignore Files¶
You can place additional .gitignore files in subdirectories. Rules in these files only apply to their respective directories.
Important Notes¶
- Not Retroactive: If a file is already tracked by Git, adding it to
.gitignorewill not stop tracking. Remove it from the repository and commit the change to fully ignore it. - Commit
.gitignore: Changes to.gitignoreshould be committed so others working on the repository benefit from the same ignore rules.
Best Practice¶
Keep your .gitignore file organized and review it regularly to ensure only necessary files are ignored.