15

in .gitignore what is the difference between using

/bin 

and

bin/ 

And how would I make it so that it removes a certain file, no matter where it is?

*/*.ext 

3 Answers 3

33

A leading / anchors the ignore pattern at the point in the tree where the particular .gitignore resides.

A trailing / means that a pattern will only match a directory (and so all the files in that matching directory).

You can have both, e.g. /bin/ will match only a directory called bin and only at the level of the .gitignore file.

A simple *.ext will match any file ending with .ext anywhere at or below the level of the .gitignore file in which it appears.

Sign up to request clarification or add additional context in comments.

Comments

6

I tested the cases and also some more ones and here you can review the results:

Results

EDIT: Corrected according to @Dan Breen's comment below (thanks!)

1 Comment

In the first row for bin, the last column for *.txt should be x since it would not be matched.
5

The latter would match "xxx/bin" and "bin" in any other subdirectories.

Answer for your edit: *.ext would take care of all files in the repository ending w/ that ext.

1 Comment

Also answer his second question, that is, he should use .ext instead of */.ext

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.