- 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
~, swap files (
.swp) or backup files named like
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
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
[core] 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
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
that will be processed globally.
gitignore for Emacs
Gitignore for Emacs editor:
# -*- mode: gitignore; -*- *~ \#*\# /.emacs.desktop /.emacs.desktop.lock *.elc auto-save-list tramp .\#* # Org-mode .org-id-locations *_archive # flymake-mode *_flymake.* # eshell files /eshell/history /eshell/lastdir # elpa packages /elpa/ # reftex files *.rel # AUCTeX auto folder /auto/ # cask packages .cask/ dist/ # Flycheck flycheck_*.el # server auth directory /server/ # projectiles files .projectile # directory configuration .dir-locals.el
gitignore for Vim
Gitignore for Vim editor:
# swap [._]*.s[a-v][a-z] [._]*.sw[a-p] [._]s[a-v][a-z] [._]sw[a-p] # session Session.vim # temporary .netrwhist *~ # auto-generated tag files tags
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.
- Emacs 18.6.3 Recovering Data from Auto-Saves https://www.gnu.org/software/emacs/manual/html_node/emacs/Recover.html
- Vim documentation: recover http://vimdoc.sourceforge.net/htmldoc/recover.html
- Github gitignore project https://github.com/github/gitignore/tree/master/Global
- Gitignore file in git documentation https://git-scm.com/docs/gitignore