Git | Local gitignore file to locally exclude files and file changes

A few days ago I wondered how I can ignore files without altering the 'repository global' .gitignore file. My intention was to keep the .gitognore file at it is and hide my workspace specific files generate by individual programmes like an IDE or other build tools not used by the project by default. Becuase I wont or could not adjust the default .gitignore these files are showing up in git like in git-gui.

How to add an workspace specific gitignore file


Es described in the Git documentation there are different ways to hide local files from the index. I combined two of them to create the perfect solution to fit my needs.

The simpliest solution is described in the linked documentation: Just use the exclude file in the git folder. This file can be found here : .git/info/exclude. Just add the to ignore filesnames and wildcards to this file and they are not longere visible within the index.

As this solution does work perfectly it is not very comfortable to manage this files in the subfolder of the hidden .git folder. By combining the exclude method with the core.excludesFile option for git as described in the linked documentation. To add a '.gitignorelocal' to your workspace root check out the description below:

A local file to define additional ignored file pattern



  1. Create the following file inside your project folder (along with the hidden .git folder) .gitignorelocal  the file will be listed as unversioned in git.

  2. Open the git exclude file. It can be found at .git/info/exclude. Append the name of your file (.gitignorelocal) to the end of this file. Save and Close. The file is now exclusivle excluded from your Git repository and should not be visible as unversioned file animore.

  3. Apply the following excludesFile key to the core section of your reposity config file found in the hidden .git folder like this:
    [core]
    excludesfile = ~/.gitignorelocal


  4. Now the content of the added file is recognized as to be ignored in Git.


 
{{ message }}

{{ 'Comments are closed.' | trans }}