Emacs .gitignore template
The Emacs template ignores the editor's three kinds of temporary file, compiled Lisp bytecode, and the project local state that packages write beside your source.
At a glance
- Category
- IDE
- Patterns in this template
- 14 rules
- Directories ignored
- None. Every rule matches by filename or extension rather than by directory.
- Also needs an OS template
- Yes. These are editor artefacts, not operating system ones.
- Typical companions
- The language template for your project, plus an OS template.
In detail
Emacs produces three distinct kinds of temporary file and this template covers all three. Files ending in a tilde are backups of the previous saved version, written next to the original every time you save unless you configure the editor otherwise. Files wrapped in hash characters are auto saves, written periodically so a crash does not lose work. Files starting with .# are lock files, and they are symbolic links whose target encodes the user and host currently editing that file.
That last detail is worth noting. A lock file is not a normal file at all, and a committed one is a dangling symbolic link pointing at a username and hostname that meant something on one machine for a few minutes. Configuring the editor to put backups and auto saves in a central directory removes the problem at the source, which is what most people eventually do.
*.elc is compiled Lisp bytecode. It is produced from the .el file next to it and it is version specific: bytecode compiled by one editor version can fail to load in another. A stale .elc that is newer than its source will also be loaded in preference to it, which produces the confusing case where editing the source changes nothing.
auto-save-list holds the index of auto save files for a session, and tramp holds cached connection state for remote editing, including the hosts and paths you connected to. /.emacs.desktop and its lock file save the set of buffers open in a session, restored on next start.
The remaining rules cover per project tooling: flycheck_*.el are temporary copies the syntax checker writes for linting, .projectile is a project definition file, .dir-locals.el holds directory scoped variables, and .org-id-locations is an index of note identifiers. .dir-locals.el is the one to reconsider, since a team that shares directory local settings deliberately may want it tracked.
Examples
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
flycheck_*.el
.projectile
.dir-locals.el
.org-id-locations
*_archive
*_flymake.*14 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- .dir-locals.el is ignored here, but it is often written on purpose to share project settings. Remove that line if your team relies on it.
- Lock files starting with .# are symbolic links to a user and host string. A committed one is a broken link rather than a file, which confuses tools that try to read it.
- A stale .elc that is newer than its .el source is loaded in preference to the source, so ignoring compiled Lisp also avoids a class of confusing bug.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →Vim .gitignore template
The Vim template uses character ranges to catch every swap file extension the editor cycles through, plus sessions, undo history and the netrw history.
Linux .gitignore template
The shortest template in the collection. Five rules covering editor backup files, file manager settings, per volume trash and NFS silly rename files.
Lua .gitignore template
A short template for a short toolchain: compiled bytecode from luac, packaged rock archives, and the local tree LuaRocks installs dependencies into.
Sublime Text .gitignore template
The Sublime template separates the project file from the workspace file, and covers sftp-config.json, which stores upload credentials in plain text.
Xcode .gitignore template
The Xcode template ignores the project bundle's contents while keeping the project file and shared data, the only way to share schemes but not sessions.
Android Studio .gitignore template
The Android Studio template ignores local.properties, which names the SDK path on one machine, along with build output, captures and native build directories.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS