How to gitignore Go binaries?

This will ignore everything except .go files, and works for subdirectories too:

**/*
!**/*.go
!**/

You may also want to check out this question, which is asking something very similar.


You need to use:

**/*.go

The ** is for ignoring files inside any folder and not only in the current folder.


A minor bug was fixed in git v2.7:

Allow a later !/abc/def to override an earlier /abc that
appears in the same .gitignore file to make it easier to express
everything in /abc directory is ignored, except for ....


From the .gitignore documentation:

Two consecutive asterisks (**) in patterns matched against full pathname may have special meaning:

Leading **

A leading ** followed by a slash means match in all directories.
For example, **/foo matches file or directory foo anywhere, the same as pattern foo.
**/foo/bar matches file or directory "bar" anywhere that is directly under directory foo.

Trailing **

A trailing /** matches everything inside.
For example, abc/** matches all files inside directory abc, relative to the location of the .gitignore file, with infinite depth.

/**/

A slash followed by two consecutive asterisks then a slash matches zero or more directories.
For example, a/**/b matches a/b, a/x/b, a/x/y/b and so on.

Tags:

Git

Gitignore