11

From my other post, I know the __pycache__ should be put into the .gitignore when I use git.

And in the other post I saw, there are also .pyc and .pyo files.

whether them should all be put into the .gitignore file?

Can we summarize in the Python/Django project, what files should be put into . gitignore file?

phd
  • 82,685
  • 13
  • 120
  • 165
qg_java_17137
  • 3,310
  • 10
  • 41
  • 84
  • It's going to be different for Python projects in general versus Django projects. General rule: things that are generated should go into `.gitignore`. I'd suggest finding some Python and Django projects on GitHub and seeing what they have in their `.gitignore`s. Also note that if you add `__pycache__/`, you don't need to add `*.pyc` and `*.pyo` unless your project runs on Python 2. –  Nov 17 '17 at 03:47

1 Answers1

24

There is a popular web service called Gitignore.io that help developers generate gitignore files for popular framework and languages. You can see the Django one here.

*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
media

On top of that I would also recommend you to ignore things environment items such as virtualenv, or .env files that are related to the local environment that the code is being run from. This also allow you to store passwords and secrets in environment files, and keep them out of your git repo.

.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

Lastly I would also add the django static folder to the list of files to ignore since it is collected with collectstatic whenever you deploy your code.

Marcus Lind
  • 10,374
  • 7
  • 58
  • 112