Gitignore

Gitignore

A gitignore file tells the Git version control system which files it should ignore when tracking changes. This way, for example, passwords, automatically generated files, or huge data packages don't accidentally end up in the shared code repository.

When developers work together on a program, they use a system called Git that records all changes to the source code — that is, the text files that make up a program — and makes them accessible to everyone involved. However, not all files in a project are meant to be tracked. Passwords, personal settings, or very large data packages don’t belong in the shared repository. This is exactly where the gitignore file comes into play: it is a simple text file named `.gitignore` that specifies which files and folders Git should silently skip. Whatever is listed there is treated by Git as if it didn’t exist at all.

Why a gitignore file is not a luxury

Without a gitignore, things quickly end up in the shared repository that have no business being there. Particularly dangerous are secrets such as API keys or database passwords — that is, credentials that allow a program to log in to a service. Once checked into Git, such data is stored in the entire version history and visible to anyone with access to the repository, even if the file is later deleted. This is a common and costly mistake: attackers automatically scan public code repositories for exactly such accidentally uploaded keys.

A second problem is size and clutter. Many tools automatically generate auxiliary files while working — for example, compiled intermediate results or downloaded libraries, which can comprise thousands of individual files. Nobody needs these in the repository, because they can be regenerated at any time. A well-maintained gitignore file keeps the repository lean and organized.

Structure and rules of a gitignore file

The file contains one pattern per line. If it says `passwords.txt`, Git ignores exactly that file. If it says `*.log`, Git ignores all files whose name ends in `.log` — the asterisk acts as a placeholder for any characters. If it says `node_modules/`, Git ignores the entire folder of that name. These patterns are called glob patterns, and they work similarly to search filters. Lines that begin with a `#` are comments and have no effect — they serve only as explanation.

The gitignore file is usually located in the main folder of a project and then applies to the entire project. However, it is also possible to place separate gitignore files in subfolders that only apply locally. Ready-made templates exist for common programming languages and tools — the service gitignore.io or the GitHub repository `github/gitignore` provide hundreds of such templates that can simply be adopted.

Important: Gitignore only protects files that Git has never tracked before. Anyone who has already saved a file with Git and then adds it to the gitignore file afterward achieves nothing — Git already knows the file and ignores the entry. In this case, the file must first be actively removed from tracking before the entry takes effect.

Gitignore in practice — from school projects to AI models

Gitignore is encountered everywhere Git is used — that is, in practically every modern software project. Anyone who uploads a first Python script to GitHub at school or at home will need it at the latest when the program uses a file containing a password. Professional teams set up the gitignore file as one of the first things in a new project, even before the first real code is written.

In AI projects, gitignore is especially important because very large files are frequently created there. Trained models — that is, the files that store the learned knowledge of an AI system — can be several gigabytes in size. Git is made for text files, not huge binary data. Such model files therefore end up in the gitignore file by default and are instead shared via specialized services like Hugging Face or dedicated file servers.

Whenever you read in tech news that a company accidentally leaked credentials, a missing or misconfigured gitignore file is very often behind it. It is one of the most common beginner mistakes — and at the same time one of the simplest to prevent with a single text file.

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.