GitIgnore for Clojure and Emacs - Ignore Emacs Backup & Temp Files

Even though I use .gitignore files to control common files that should not be committed to a git repository, its very easy to forget about the backup or temporary files that my development tools generate. As these auto-generated files are development tool specific, they are not always included in a .gitignore file.

Especially when you are under pressure to commit changes or deploy your code its easy to include a few things you dont need, especially when using the commands git add . or git commit -am "".

So when I discovered the idea of using a .gitignore_global file, I quicky adopted this and saved myself a lot of time with this simple approach.

Whilst I could simply add the patterns to the git repository .gitignore file, however this is not very effective for three reasons.

  1. I’m adding my own preferences to a project I’m sharing with others, who may have different toolset.

  2. I have to add this to each new project I create / clone / fork.

  3. Pull requests can be confusing or simply rejected by unneccessary changes to .gitignore files

After a little more discovery with Git, I found that .gitignore_global is a better way to exclude files that were specific to my tools and environment than individual project .gitignore files.

Creating my own global ignores

Emacs is the tool I used for my Clojure development, as well as writning contnet in markdown and Org-mode. As all these types of files are versioned in Git, then there is a lot of potential for backup files to sneak in.

So in the ~/.gitconfig of my home directory I have a section called [core] where a global excludes file is defined

1
2
3
[core]
excludesfile = /Users/jstevenson/.gitignore_global
editor = emacsclient

By adding file name patters to the .gitignore_global file for Emacs, I can add my own personal excludes without adding unneccessary stuff to each project I work on. It also means its one less thing to remember when I am working with git projects.

My ~/.gitignore_global file now contains the following filename patterns, the last three patterns are specifically for the Emacs temporary and backup files.

1
2
3
4
5
*~
.DS_Store
*~
*#
.#*

Keeping project .gitignore files clean

Now when I work with Clojure projects using Emacs, I can commit away without having to worry about my editor add things that I carelessly add when in a hacking frenzy!

This also keeps the .gitignore files specific to a project much smaller and project specific.

1
2
3
4
5
6
7
8
9
pom.xml
*jar
/classes/
/.lein-deps-sum
/.lein-failures
/.lein-env
/checkouts
/.env
/target

Finally, by minimising the changes in the project .gitignore file this limits the amount of times that file needs to be committed to the version control system. It is less likely that a change in the .gitignore file end up in code change commits.

See the github/gitignore repository for examples of language and build tool specific gitignore patterns.

Thank you.
@jr0cket


This work is licensed under a Creative Commons Attribution 4.0 ShareAlike License, including custom images & stylesheets. Permissions beyond the scope of this license may be available at @jr0cket
Creative Commons License