Setting up a global .gitignore for Python projects on Mac OS X

If you are working on a lot of Python projects and are using Git version control, it is very convenient to set up a global .gitignore file that ignores often occurring file types like .pyc and .egg that you generally don’t want to have in your repository.

Ignoring common python files not wanted in your repository

First make a file .gitignore in your home directory (touch ~/.gitignore) and include the following:

.DS_Store

*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

Then make sure to add this .gitignore file to Git with the following command:

git config --global core.excludesfile '~/.gitignore'

If all went right, now files like .pyc and .egg are not included in Git repositories!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>