Key concepts

.gitignore file

In Git, a .gitignore file is a text file that tells Git which files and directories to ignore when tracking changes in a repository. You can use a .gitignore file to exclude files that are generated during the build process, contain sensitive information, or are not relevant to the project.

Where to place the file

  1. Root of the repository: The .gitignore file should be placed in the root directory of your repository. This ensures that Git applies the ignore rules to all files and directories in the repository.

  2. Subdirectories: You can also create .gitignore files in subdirectories to specify ignore rules that only apply to files in that directory and its subdirectories.

Global ignore file

In addition to your project's ignore file, Git also uses a global ignore file that applies to all repositories on your system. The path to the global ignore file is stored in the core.excludesFile configuration variable.

Find out the location of the global ignore file:

git config --global core.excludesFile

Example

File: .gitignore
# Add comments for clarity. Comments start with a hash (#) symbol.
# This is a comment!
 
# Ignore files with specific names.
Thumbs.db
.DS_Store
 
# Ignore files with specific extensions. The * is a wildcard that matches
# any characters.
*.log
*.tmp
*.bak
 
# Ignore directories. The trailing slash is not required, but it better
# indicates a directory for the reader.
logs
temp/
 
# Ignore files in any directory with a specific name.
# The ** pattern matches any directory, including subdirectories.
**/build/
 
# Ignore files with a specific name in a specific directory.
docs/*.pdf
 
# Ignore all files in a directory except for one specific file
# The ! prefix negates the pattern, so the file is not ignored.
config/*
!config/main.conf
 
# Include a previously ignored file using the ! prefix.
!important.log
© 2024-2025 GitByBit.All rights reserved.

Hi! I'm Alex, creator of GitByBit.

And this is Gitopedia—a reference that summarizes knowledge in my Git course.

Gitopedia is designed to be a personal knowledge base. When you progress through the main Git course in VS Code, you unlock all of these topics, one by one, bit by bit. This gives you time to digest the information and gradually build the mental model of Git. Here's an example of how it works:

Learning directly in VS Code lets you practice Git exactly as you would in real life, doing real jobs, writing real code. In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.

The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.

Learn Git in VS Code