.gitignore for OCaml

19 ignore rules for OCaml, ready to copy into your repository.

Multi-paradigm programming language

The complete .gitignore for OCaml

# Generated by LFGitignore - https://lfgitignore.com
# Created: 2026-05-15 11:15:41 UTC
# Technologies: OCaml

### OCaml ###
*.annot
# Static library
*.a
*.cma
*.cmi
*.cmo
*.cmx
*.cmxa
*.cmxs
*.cmt
*.cmti
_build/
*.byte
setup.data
setup.log
*.native
.merlin
*.install
# Object file
*.o
_opam/

What these OCaml rules actually ignore

Every pattern below, and why it belongs in your .gitignore.

General

Pattern What it ignores
*.annot General
*.a Static library
*.cma General
*.cmi General
*.cmo General
*.cmx General
*.cmxa General
*.cmxs General
*.cmt Files containing detailed information about the compilation (generated by `ocamlc`/`ocamlopt` when invoked using the option `-bin-annot`). These files are typically useful for code inspection tools (e.g. Merlin).
*.cmti General
_build/ General
*.byte ocamlbuild targets
setup.data oasis generated files
setup.log General
*.native General
*.o Object file

Merlin configuring file for Vim and Emacs

Pattern What it ignores
.merlin Merlin configuring file for Vim and Emacs

Dune generated files

Pattern What it ignores
*.install Dune generated files

Local OPAM switch

Pattern What it ignores
_opam/ Local OPAM switch

How to use this .gitignore for OCaml

  1. Copy the OCaml rules above, or download the file directly.
  2. Create a file named .gitignore at the root of your Git repository and paste the rules into it.
  3. If some of those files are already tracked, run git rm -r --cached . then commit again — Git only applies ignore rules to untracked files.
  4. Commit the .gitignore so everyone on the team shares the same rules.

Other Language .gitignore templates

See every Language template