Make Git Ignore Temporary Files Produced By Emacs And Vim In All Directories Globally
Overview
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.
[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.
gitignore
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; -*-
*~
\#*\#
/.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.
Conclusion
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.
References
- 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
- Make Git Ignore Temporary Files Produced By Emacs And Vim In All Directories Globally
- How to Contribute To A Github Repository in 6 StepsNovember 10, 2016
Git commands
- Git CommandsJune 24, 2016
Git Common Use Cases
- Creating a git server from a git repoJuly 1, 2016
- Showing Untracked Files In Status After Creating New Directories In GitJanuary 2, 2016
Git Concepts
- Git Basic ConceptsJune 24, 2016
Git remotes
- RemotesJune 24, 2016
Articles
Subcategories
Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.
Powered by SimpleIT Hugo Theme
·