Last Updated: January 2, 2023
Gitignore is a file in a Git repository that tells Git which files or directories to ignore when committing changes. Ignoring certain files and directories can be useful when you have files that are generated automatically or are specific to your local development environment and you don’t want to commit them to the repository.
To create a .gitignore file in your repository, follow these steps:
- Create a new file in your repository called “.gitignore”.
- Open the .gitignore file in a text editor and add the names of the files or directories you want to ignore, one per line. You can use wildcards to ignore multiple files at once. For example, to ignore all files with the “.tmp” extension, you would add “*.tmp” to the .gitignore file.
- Save the .gitignore file and commit it to the repository.
Once you have added a .gitignore file to your repository, Git will automatically ignore any files or directories that are listed in it when you commit changes. If you want to stop ignoring a file or directory, you can simply remove it from the .gitignore file and commit the changes.
It’s also worth noting that you can create a global .gitignore file that applies to all of your Git repositories. This can be useful if you have certain files or directories that you want to ignore in all of your projects. To create a global .gitignore file, you can use the following command: