Make Git Ignore Temporary Files Produced By Emacs And Vim In All Directories Globally

  • Published: January 9, 2017


Using VIm and Emacs on a daily basis is very common for programmers.

They have recovering systems to avoid losing work if a computer crashes, that would make your directories full of strange files ending in ~, swap files (.swp) or backup files named like #<filename>#.

Those files would appear from time to time in your git status listings that wouldn’t add any valuable information.

Better than disabling them, is to avoid seeing them globally, so any new git repository won’t show them in the status of changed file list but you will still be able to recover them if anything bad happens while editing.

Enabling gitignore globally

We will set up a global .gitignore_global file, i.e.: a list of rules for ignoring files in every Git repository on the computer.

$ git config --global core.excludesfile ~/.gitignore_global

This command will automatically set the following configuration in your ~/.gitconfig_global file.

        excludesfile = /home/user/.gitignore_global

Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.


Github has a great project with useful .gitignore files optimized for a Operating System and editor specific.

We grab the ones for Emacs and Vim (I don’t think you ever need any other editor ;)

You should put them together in a single ~/.gitignore_global file that will be processed globally.

gitignore for Emacs

Gitignore for Emacs editor:

# -*- mode: gitignore; -*-

# Org-mode

# flymake-mode

# eshell files

# elpa packages

# reftex files

# AUCTeX auto folder

# cask packages

# Flycheck

# server auth directory

# projectiles files

# directory configuration

gitignore for Vim

Gitignore for Vim editor:

# swap
# session
# temporary
# auto-generated tag files

Other global gitignore properties

Other common .gitignore configurations are also available in Github’s gist that may worth adding them to the global gitignore file.


Now every time you work in a new or old project you won’t have to deal with any backup files automatically generated by Vim or Emacs.


Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus
Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 ·