ReynierPM ReynierPM - 1 month ago 12
Git Question

How to properly exclude all the files or just one in a given directory?

I have the following directory structure:

$ tree config/
config/
├── config.ini
├── help.ini
└── services.yaml


This is part of a Git project but in the
.gitignore
file I am seeing the following:

config/*
/config/config.ini
config/config.ini


As a result the file
config/config.ini
is on the repository when it shouldn't be.

What's the right way to exclude all the files under
config/
and how to delete them from the upstream?

Answer

First, delete (or move out of the repository) config.ini (+ any others you want to exclude) and make a commit.

Next, change your .gitignore to simply look like this:

config

(assuming .gitignore and config/ are at the same level)

Commit the change for your .gitignore file.

All changes to anything in config/ from here on out should not be tracked.