Git Ignore

Git ignore is a feature of the Git version control system that allows you to specify files or directories that should be ignored by Git

When you ignore a file or directory, Git will not track any changes made to it, and it will not be included in your commits or pushed to the remote repository.

To ignore a file or directory in Git, you need to create a file named .gitignore in the root directory of your Git repository. In this file, you can list the files or directories that you want to ignore, using patterns or specific file names.

For example, to ignore all files with the extension .log in the root directory of your Git repository, you would add the following line to your .gitignore file:

*.log

You can also ignore entire directories by adding their names to the .gitignore file. For example, to ignore a directory named installed_binaries, you would add the following line:

installed_binaries/

Once you have added the files or directories to ignore to your .gitignore file, Git will automatically ignore them when you perform any Git operations, such as committing changes or pushing to the remote repository.

Where to locate the .gitignore file

The .gitignore file should be located in the root directory of your Git repository. This is the top-level directory that contains all the files and directories you want to track with Git.

If you have subdirectories within your repository that contain files or directories you want to ignore, you can also create additional .gitignore files in those subdirectories. The rules in these subdirectory .gitignore files will apply only to the files and directories within that specific subdirectory.

It’s important to note that the rules in .gitignore files are not retroactive. This means that if you add a rule to ignore a file after it has already been committed to the repository, the file will still be tracked by Git. To remove the file from the repository, you will need to first delete it from your local repository, then commit the deletion to the remote repository.

Also, if you make changes to the .gitignore file, you’ll need to commit those changes to the repository in order for them to take effect.

Last modified July 21, 2024: update (e2ae86c)