Setting up a local gitignore file

Setting up a local gitignore file

Setting up a local gitignore file

Sometimes, you need Git to ignore files that only matter on your machine, such as editor configuration files, temporary scripts, and local environment files, without polluting the shared .gitignore file that the rest of the team relies on. Git supports creating a local ignore file with patterns that apply only to your copy of the repository and never get committed. This is useful for keeping the main .gitignore clean and avoiding the addition of unnecessary patterns to it.

Steps

1 Create the local gitignore file. Next, change directories into your repo and run this command to edit your local git configuration:

git config --local -e

2 That command will open the default text editor configured in git. Add the path to the local gitignore file you created in step 1 to the [core] section of the configuration:

# Under the [core] section, add
excludesfile = /path/to/your/local_gitignore # replace this with a path to your local gitignore file

3 The excludes file doesn’t have to be in the same repo or directory as your project. As long as the path pointed to in the excludesfile is valid, git will read its contents and ignore the patterns in it.

Conclusion

A simple addition like this helps keep your repo clean and avoids inadvertently adding temporary or experimental files to the project’s history.

Leave a Reply