Git Ignore¶
This guide explains how to use
.gitignore
to 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
.gitignore
file in the root of your repository. - Add patterns or file names for files and directories you want to ignore.
Examples¶
- Ignore all
.log
files: - 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
.gitignore
will not stop tracking. Remove it from the repository and commit the change to fully ignore it. - Commit
.gitignore
: Changes to.gitignore
should 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.