gogitignore

The other day I extended one of my go (golang) project with some new main packages resulting in new commands. After building the project with go build the resulting executables are placed in the respective directories within the project. While updating the git repository I found it cumbersome to add all the new executables to the .gitignore-file. On linux there is unfortunately now easy way to exclude all executables within a project with a single line in .gitignore.

With go it is easily predictable how the resulting executables from a main package are named. The directory name, containing a main package, will be used as filename for the new command. Hence I hacked some lines of go code to automatically update the .gitignore file. The result is the gogitignore. At the moment it still a bit rough around the edges, but the main idea is already implemented.

Usage

In the easiest case you may just run gogitignore in the root directory of your go project. This will add all executables, build from the main packages, automatically as an entry to the .gitignore file in the project root directory. To double check the result gogitignore provides the flag -stdout (or -dryrun).

For more information about the usage run gogitignore -h:

-dir=".": destination directory where .gitignore is located and where to traverse directory tree for go programs.
-dryrun=false: dryrun, no changes are made
-exec=false: find all files with executable bit set
-gomain=true: add executables, resulting from building go main packages
-h=false: print usage
-help=false: print usage
-inplace=false: edit .gitignore in place